Skip to content

[video_player] Implement screen auto-lock control for video playback#11225

Merged
auto-submit[bot] merged 20 commits into
flutter:mainfrom
shrabanti722:video-player-screen-auto-lock
Jul 13, 2026
Merged

[video_player] Implement screen auto-lock control for video playback#11225
auto-submit[bot] merged 20 commits into
flutter:mainfrom
shrabanti722:video-player-screen-auto-lock

Conversation

@shrabanti722

@shrabanti722 shrabanti722 commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

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

  • Add preventsDisplaySleepDuringVideoPlayback to VideoPlayerOptions (default: true to preserve existing behavior)
  • When false, the screen can auto-lock during playback
  • Implemented on iOS/macOS via AVPlayer.preventsDisplaySleepDuringVideoPlayback
  • Platform interface: setPreventsDisplaySleepDuringVideoPlayback(int playerId, bool preventsDisplaySleepDuringVideoPlayback)

Usage

VideoPlayerController.networkUrl(
  url,
  videoPlayerOptions: VideoPlayerOptions(preventsDisplaySleepDuringVideoPlayback: false),
);

Breakout PRs

  1. Platform interface: [video_player_platform_interface] Add preventsDisplaySleepDuringVideoPlayback option #11546
  2. AVFoundation (iOS/macOS): [video_player_avfoundation] Implement preventsDisplaySleepDuringVideoPlayback #11547

Issues fixed

  • Fixes: flutter/flutter#183520 (How to disable wakelock on iOS side?)
  • Addresses the need to allow screen auto-lock during video playback on iOS (e.g. for ambient/background videos)

Pre-Review Checklist

- 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.
…ontrol for video playback in the video player packages.
@google-cla

google-cla Bot commented Mar 11, 2026

Copy link
Copy Markdown

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.

@shrabanti722 shrabanti722 changed the title Video player screen auto lock [video_player] Implement screen auto-lock control for video playback Mar 11, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 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.

Comment thread packages/video_player/video_player/lib/video_player.dart Outdated
Comment thread packages/video_player/video_player/pubspec.yaml Outdated
Comment thread packages/video_player/video_player_avfoundation/pubspec.yaml Outdated

@LouiseHsu LouiseHsu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like you have some compilation errors.

https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8687630786392823857/+/u/Run_package_tests/drive_examples/stdout

../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(

@JetA2

JetA2 commented Mar 12, 2026

Copy link
Copy Markdown

Thanks for the PR, I was just looking at this issue.
For my use case, it would be preferable to have this feature on the VideoPlayerControllerinstead of VideoPlayerOptions, otherwise you have to create a new controller if you want to change the value of the setting.

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.
shrabanti722 and others added 3 commits March 14, 2026 17:12
…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>
@LouiseHsu LouiseHsu added the CICD Run CI/CD label Mar 16, 2026
@mdebbar
mdebbar removed their request for review March 18, 2026 16:05
@@ -1,3 +1,7 @@
## 2.9.5

* Implement screen auto-lock control for video playback.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implements

@shrabanti722

Copy link
Copy Markdown
Contributor Author

@stuartmorgan-g updated AvFoundation child PR to ready for review.

@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

From triage: This is just waiting on #11547 which is under review.

auto-submit Bot pushed a commit that referenced this pull request Jul 9, 2026
…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.
@shrabanti722

Copy link
Copy Markdown
Contributor Author

@stuartmorgan-g, I have removed all temporary dependency_overrides. Let me know if anything else needs to be done.

@stuartmorgan-g stuartmorgan-g added the CICD Run CI/CD label Jul 10, 2026
@stuartmorgan-g
stuartmorgan-g dismissed LouiseHsu’s stale review July 10, 2026 16:39

Addressed in sub-PR

@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

This will just need final re-approval by @tarrinneal to land.

@tarrinneal

Copy link
Copy Markdown
Contributor

You'll need to run dart format again before this can land.

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.
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Jul 11, 2026
@shrabanti722

Copy link
Copy Markdown
Contributor Author

@tarrinneal reformatted with dart format

@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

That commit didn't change any formatting. You'll need to either format on a current master, or manually apply this diff.

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.
@shrabanti722
shrabanti722 force-pushed the video-player-screen-auto-lock branch from cfcfc0d to cdfc331 Compare July 13, 2026 18:08
@shrabanti722

shrabanti722 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@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.

@stuartmorgan-g stuartmorgan-g added autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD labels Jul 13, 2026
@auto-submit
auto-submit Bot merged commit e8903cb into flutter:main Jul 13, 2026
91 checks passed
Mairramer pushed a commit to Mairramer/flutter that referenced this pull request Jul 15, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD federated: all_changes PR that contains changes for all packages for a federated plugin change p: video_player

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[video_player] Allow screen auto-lock during video playback on iOS

8 participants