[video_player] Implement screen auto-lock control for video playback#11225
Conversation
- Added `setAllowScreenAutoLock` method to the video player platform interface and its implementations for iOS. - Updated `VideoPlayerOptions` to include `allowScreenAutoLock` property. - Modified the `AVFoundationVideoPlayer` class to handle screen auto-lock settings during playback. - Added tests to verify the functionality of screen auto-lock settings. This feature allows users to control whether the screen should stay awake during video playback on iOS devices.
- Removed redundant player ID assignment and completer initialization from the `VideoPlayerController` class. - Enhanced code clarity by consolidating player setup logic. - This change improves maintainability and readability of the video player implementation.
Made-with: Cursor
…ontrol for video playback in the video player packages.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request introduces a new feature to control screen auto-locking during video playback by adding an allowScreenAutoLock option. The changes are implemented across the platform interface, the main video_player package, and the video_player_avfoundation implementation for iOS and macOS. My review has identified a few areas for improvement: a potential bug in the macOS implementation's availability check, a style guide violation regarding dependency_overrides in pubspec.yaml files, and opportunities for enhancing code clarity and documentation.
LouiseHsu
left a comment
There was a problem hiding this comment.
looks like you have some compilation errors.
../lib/video_player.dart:594:34: Error: The method 'setAllowScreenAutoLock' isn't defined for the type 'VideoPlayerPlatform'.
- 'VideoPlayerPlatform' is from 'package:video_player_platform_interface/video_player_platform_interface.dart' ('../../../../../.pub-cache/hosted/pub.dev/video_player_platform_interface-6.6.0/lib/video_player_platform_interface.dart').
Try correcting the name to the name of an existing method, or defining a method named 'setAllowScreenAutoLock'.
await _videoPlayerPlatform.setAllowScreenAutoLock(
|
Thanks for the PR, I was just looking at this issue. In my use case I have a video playing in a list without sound ("background mode" that should allow the device to auto-lock), but when it's tapped will go to full screen with sound ("foreground mode" that should keep the device awake). If I were to recreate the controller when moving to fullscreen, the playback would be interrupted. |
…ckages to use relative paths for local dependencies. This change is for testing and initial review only; do not merge.
…layer_avfoundation/Sources/video_player_avfoundation/FVPVideoPlayer.m Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…o_player_platform_interface.dart Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
| @@ -1,3 +1,7 @@ | |||
| ## 2.9.5 | |||
|
|
|||
| * Implement screen auto-lock control for video playback. | |||
|
@stuartmorgan-g updated AvFoundation child PR to ready for review. |
|
From triage: This is just waiting on #11547 which is under review. |
…Playback (#11547) ## Description Implements the `setPreventsDisplaySleepDuringVideoPlayback` platform interface method using `AVPlayer.preventsDisplaySleepDuringVideoPlayback` on iOS and macOS. AVFoundation implementation breakout PR for #11225. ## Dependencies - **Depends on the `video_player_platform_interface` 6.7.0 breakout PR.** CI will fail until that PR lands and the new interface version is published. Keeping this PR in draft until then. ## Changes - Implements `setPreventsDisplaySleepDuringVideoPlayback` in `FVPVideoPlayer.m` and wires it through the Dart platform implementation. - Adds the Pigeon method definition and regenerates messages (includes a pigeon v26.1.7 → v26.2.3 bump carried over from the parent PR). - Bumps `video_player_avfoundation` to 2.10.0 and updates the `video_player_platform_interface` constraint to ^6.7.0. - Updates CHANGELOG. ## Related - Parent PR: #11225 - Fixes: flutter/flutter#183520
…ished versions Now that flutter#11546 (video_player_platform_interface 6.8.0) and flutter#11547 (video_player_avfoundation 2.11.0) have landed, drop the landed child-PR changes from this branch, remove the 'FOR TESTING AND INITIAL REVIEW ONLY' dependency_overrides, and depend on the published versions instead.
|
@stuartmorgan-g, I have removed all temporary dependency_overrides. Let me know if anything else needs to be done. |
|
This will just need final re-approval by @tarrinneal to land. |
|
You'll need to run |
Resolves conflicts with upstream/main, which released video_player 2.12.0 (backBufferDurationMs) and raised the SDK floor to Dart 3.12 / Flutter 3.44: - Moves the preventsDisplaySleepDuringVideoPlayback feature to a new 2.13.0 CHANGELOG entry (2.12.0 is now upstream's backBufferDurationMs release). - Updates dependencies to the published versions: video_player_android ^2.11.0, video_player_avfoundation ^2.11.0, video_player_platform_interface ^6.9.0. - Reformats with dart format under the new Dart 3.12 formatter, fixing the repo_checks format failure.
|
@tarrinneal reformatted with |
|
That commit didn't change any formatting. You'll need to either format on a current |
test/video_player_test.dart: block-style list required by the Dart formatter on Flutter master; applied manually per reviewer since local stable (3.12.2) formats it differently.
cfcfc0d to
cdfc331
Compare
|
@stuartmorgan-g sorry I overlooked it, my earlier commit fixed the merge conflicts and my local dart format on 3.12.2 showed no diff. I have now manually applied the formatting diff. Thank you. |
…r#189509) flutter/packages@ad2eab1...9f95026 2026-07-15 [email protected] [google_fonts] Extract the config class to its own file (flutter/packages#12202) 2026-07-14 [email protected] Update All Flutter Android Example Apps to 3.47 Template Versions (flutter/packages#12195) 2026-07-14 [email protected] Roll Flutter from cf9e8af to 846664b (24 revisions) (flutter/packages#12200) 2026-07-14 [email protected] [go_router_builder] Support analyzer 13 (flutter/packages#12189) 2026-07-14 [email protected] [shared_preferences] Convert legacy tests to Kotlin (flutter/packages#12193) 2026-07-13 [email protected] [material_ui, cupertino_ui] Migrate `@macro`s that are defined in Material and used in Cupertino (flutter/packages#12197) 2026-07-13 [email protected] [material_ui, cupertino_ui] Add `#region` to example files to remove license headers (flutter/packages#12170) 2026-07-13 [email protected] [video_player] Implement screen auto-lock control for video playback (flutter/packages#11225) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Description
Adds support for screen auto-lock during video playback on iOS.
By default, the video player keeps the screen awake during playback. Some apps (e.g. login screens with background videos, ambient content) want the screen to be able to auto-lock while video plays. This PR adds an option to allow that behavior.
Changes
preventsDisplaySleepDuringVideoPlaybacktoVideoPlayerOptions(default:trueto preserve existing behavior)false, the screen can auto-lock during playbackAVPlayer.preventsDisplaySleepDuringVideoPlaybacksetPreventsDisplaySleepDuringVideoPlayback(int playerId, bool preventsDisplaySleepDuringVideoPlayback)Usage
Breakout PRs
Issues fixed
Pre-Review Checklist
[video_player]///).