-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[video_player] Add background playback with media notification support #10915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[video_player] Add background playback with media notification support #10915
Conversation
Adds the ability for video playback to continue when the app is backgrounded, with optional system media notification controls on Android and iOS/macOS. Features: - New `allowBackgroundPlayback` option in `VideoPlayerOptions` - New `NotificationMetadata` class for customizing media notification - System media controls (play/pause/seek) on lock screen and control center - `updateNotificationMetadata()` method for dynamic metadata updates Platform support: - Android: Uses Media3 MediaSession with foreground service - iOS/macOS: Uses MPNowPlayingInfoCenter and MPRemoteCommandCenter - Web: Not supported (returns false for availability check)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces background playback with system media notification support for the video_player plugin across Android, iOS, and macOS. The web platform explicitly opts out of this feature. The changes include adding new API methods in video_player_platform_interface for setting and updating notification metadata, as well as platform-specific implementations for Android (using Media3 MediaSession) and iOS/macOS (using MPNowPlayingInfoCenter and MPRemoteCommandCenter). The necessary Pigeon-generated code and test cases have been updated accordingly. Resource cleanup for background playback is also handled during player disposal.
| final VideoPlayerOptions? options = videoPlayerOptions; | ||
| final NotificationMetadata? metadata = options?.notificationMetadata; | ||
| if (options != null && options.allowBackgroundPlayback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variables options and metadata are redundant here. You can directly access videoPlayerOptions and videoPlayerOptions?.notificationMetadata within the if condition, making the code slightly more concise.
if (videoPlayerOptions != null && videoPlayerOptions.allowBackgroundPlayback) {
await _videoPlayerPlatform.setBackgroundPlayback(
_playerId,
enableBackground: true,
notificationMetadata: videoPlayerOptions.notificationMetadata,
);
}|
Thanks for the contribution! This appears to be substantially expanding the scope of Setting to Draft status for now, since the design document review should happen before code review. |
Remove setBackgroundPlayback() and isBackgroundPlaybackSupportAvailable() methods. Background playback is now automatically enabled when notificationMetadata is provided in VideoPlayerOptions during initialization.
Adds system media notification support for background playback, allowing users to control video playback from the lock screen, notification shade, and control center.
Features:
NotificationMetadataclass for customizing media notification contentnotificationMetadataparameter inVideoPlayerOptionsto enable notificationsupdateNotificationMetadata()method for dynamic metadata updates during playbackPlatform support:
Fixes flutter/flutter#62739
Pre-Review Checklist
[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2 ↩3