[video_player] Implement screen auto-lock control for video playback#11225
[video_player] Implement screen auto-lock control for video playback#11225shrabanti722 wants to merge 17 commits intoflutter:mainfrom
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. | |||
…uring video playback.
… screen sleep during video playback.
…essages for improved readability.
|
Thanks @shrabanti722 for this feature. we also need this option in our app badly : ) |
|
https://ci.chromium.org/ui/p/flutter/builders/try/Linux%20repo_checks/22937/overview Can you make sure your changelog + pubspec is up to date? also make sure to run |
tarrinneal
left a comment
There was a problem hiding this comment.
A couple changelog adjustments and doc comment changes, This should be good to break out into child pr's.
| @@ -1,5 +1,6 @@ | |||
| ## 2.11.1 | |||
There was a problem hiding this comment.
This will need to be a new entry in the changelog along with a version bump to 2.12.0
| @@ -1,5 +1,6 @@ | |||
| ## NEXT | |||
| ## 6.6.1 | |||
| # NOTE: We strongly prefer non-breaking changes, even at the expense of a | ||
| # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes | ||
| version: 6.6.0 | ||
| version: 6.6.1 |
| /// currently no way to implement this feature in this platform). | ||
| final bool mixWithOthers; | ||
|
|
||
| /// Set this to true to prevent the screen from sleeping during video playback. |
There was a problem hiding this comment.
Here and everywhere else this comment is located:
"Whether the screen is prevented from from sleeping during video playback."
| final bool mixWithOthers; | ||
|
|
||
| /// Set this to true to prevent the screen from sleeping during video playback. | ||
| /// The default value is true. |
There was a problem hiding this comment.
There should be an empty line between this and the line above it. (for all versions of this comment
| @@ -1,3 +1,7 @@ | |||
| ## 2.9.5 | |||
| # the parent directory to use the current plugin's version. | ||
| path: ../ | ||
| video_player_platform_interface: ^6.6.0 | ||
| video_player_platform_interface: ^6.7.0 |
| flutter: | ||
| sdk: flutter | ||
| video_player_platform_interface: ^6.6.0 | ||
| video_player_platform_interface: ^6.7.0 |
| # the parent directory to use the current plugin's version. | ||
| path: ../ | ||
| video_player_platform_interface: ^6.6.0 | ||
| video_player_platform_interface: ^6.7.0 |
| flutter: | ||
| sdk: flutter | ||
| video_player_platform_interface: ^6.3.0 | ||
| video_player_platform_interface: ^6.7.0 |
| flutter_web_plugins: | ||
| sdk: flutter | ||
| video_player_platform_interface: ^6.4.0 | ||
| video_player_platform_interface: ^6.7.0 |
…across multiple packages
…multiple packages
|
The tests are failing due to version issues. How to proceed forward ? Should I create a child PR with the version updates ? @LouiseHsu @tarrinneal |
…Playback option Adds the `preventsDisplaySleepDuringVideoPlayback` field to `VideoPlayerOptions` and a `setPreventsDisplaySleepDuringVideoPlayback` method to `VideoPlayerPlatform`, allowing platform implementations to control whether the display sleeps during video playback. Platform interface breakout PR for flutter#11225. Made-with: Cursor
…Playback option Adds the `preventsDisplaySleepDuringVideoPlayback` field to `VideoPlayerOptions` and a `setPreventsDisplaySleepDuringVideoPlayback` method to `VideoPlayerPlatform`, allowing platform implementations to control whether the display sleeps during video playback. Platform interface breakout PR for flutter#11225. Made-with: Cursor
…Playback Implements the platform interface method `setPreventsDisplaySleepDuringVideoPlayback` using `AVPlayer.preventsDisplaySleepDuringVideoPlayback` on iOS and macOS. AVFoundation implementation breakout PR for flutter#11225. Depends on the platform interface breakout PR (6.7.0). Made-with: Cursor
|
Hi @tarrinneal @LouiseHsu — I've split this into child PRs:
|
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]///).