Skip to content

[video_player_platform_interface] Add preventsDisplaySleepDuringVideoPlayback option#11546

Open
shrabanti722 wants to merge 8 commits into
flutter:mainfrom
shrabanti722:video-player-prevents-display-sleep-interface
Open

[video_player_platform_interface] Add preventsDisplaySleepDuringVideoPlayback option#11546
shrabanti722 wants to merge 8 commits into
flutter:mainfrom
shrabanti722:video-player-prevents-display-sleep-interface

Conversation

@shrabanti722

Copy link
Copy Markdown

Description

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

Changes

  • Adds preventsDisplaySleepDuringVideoPlayback field to VideoPlayerOptions (defaults to true to preserve existing behavior).
  • Adds setPreventsDisplaySleepDuringVideoPlayback(int playerId, bool preventsDisplaySleepDuringVideoPlayback) method to VideoPlayerPlatform with a default no-op implementation so existing platform implementations continue to compile without changes.
  • Updates CHANGELOG (6.7.0) and pubspec version.
  • Adds unit test covering the default value of preventsDisplaySleepDuringVideoPlayback.

Related

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

Copy link
Copy Markdown

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 updates the video_player_platform_interface to version 6.7.0, adding preventsDisplaySleepDuringVideoPlayback to VideoPlayerOptions and a corresponding method to VideoPlayerPlatform. Review feedback suggests restoring a removed CHANGELOG entry regarding SDK versions and ensuring the new interface method throws an UnimplementedError for consistency with existing methods.

Comment thread packages/video_player/video_player_platform_interface/CHANGELOG.md Outdated
Comment on lines +128 to +133
Future<void> setPreventsDisplaySleepDuringVideoPlayback(
int playerId,
bool preventsDisplaySleepDuringVideoPlayback,
) {
return Future<void>.value();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For consistency with other methods in this class (such as setMixWithOthers, setAllowBackgroundPlayback, and setWebOptions), this method should throw an UnimplementedError instead of returning a no-op Future. This ensures that platform implementations are explicitly notified if they haven't implemented the method when it's called, rather than failing silently.

Suggested change
Future<void> setPreventsDisplaySleepDuringVideoPlayback(
int playerId,
bool preventsDisplaySleepDuringVideoPlayback,
) {
return Future<void>.value();
}
Future<void> setPreventsDisplaySleepDuringVideoPlayback(
int playerId,
bool preventsDisplaySleepDuringVideoPlayback,
) {
throw UnimplementedError(
'setPreventsDisplaySleepDuringVideoPlayback() has not been implemented.',
);
}

…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
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

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

@stuartmorgan-g 2nd rev

@stuartmorgan-g stuartmorgan-g added the federated: partial_changes PR that contains changes for only a single package of a federated plugin change label May 4, 2026
///
/// Defaults to `true`.
///
/// This option is currently only supported on iOS and macOS.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This comment should not be here; a platform interface cannot make claims about implementations, because they are part of another package that this doesn't control the version of.

It's fine to say that something may not be supported on all platforms, because that's a generic statement that won't become inaccurate if other packages change, but not to say specific things about which ones do and don't.

Replace the preventsDisplaySleepDuringVideoPlayback dartdoc sentence that named
specific platforms with generic wording, per platform interface conventions.

CHANGELOG: note the clarification under 6.7.0.
@shrabanti722

shrabanti722 commented May 17, 2026

Copy link
Copy Markdown
Author

@stuartmorgan-g are there any more changes needed from my side ?

@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

@shrabanti722 I can't review the PR in its current state, as you have uploaded commits with a co-author that doesn't have a signed CLA entry. We can only review PRs that pass the CLA check.

@shrabanti722 shrabanti722 force-pushed the video-player-prevents-display-sleep-interface branch from 72b79dc to 0459c0f Compare May 22, 2026 08:55
@shrabanti722

Copy link
Copy Markdown
Author

@stuartmorgan-g fixed it.

@stuartmorgan-g stuartmorgan-g left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@stuartmorgan-g stuartmorgan-g added autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD labels Jun 9, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 9, 2026
@auto-submit

auto-submit Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/packages/11546, because - The status or check suite Linux repo_checks has failed. Please fix the issues identified (or deflake) before re-applying this label.

@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

Unfortunately, due to the delay the code in this PR will need to be re-autoformatted, as the line length for the repo changed. Sorry about that.

Once it's updated we can land it.

Re-run `dart format` after the repo's analysis_options.yaml page_width
changed from 80 to 100 in flutter#11692.
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 10, 2026
@shrabanti722

Copy link
Copy Markdown
Author

@stuartmorgan-g reformatted.

int playerId,
bool preventsDisplaySleepDuringVideoPlayback,
) {
throw UnimplementedError(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry, I missed this in the previous review. It looks like the main PR plans to only implement this for some platforms.

A feature cannot both throw an error when not implemented, and not have a support query, because otherwise there is no way for a client to know whether or not it is safe to call the method.

Is the desired behavior for this feature that it silently no-ops if not implemented, or do clients need to know whether it is going to work?

/cc @tarrinneal

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

switched the default to a silent no-op.

Per review feedback: a method cannot both throw UnimplementedError and
lack a support query, since clients have no way to know whether it is
safe to call. Switch the default to a silent no-op so platforms that
do not support controlling display sleep gracefully fall back to their
default behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

federated: partial_changes PR that contains changes for only a single package of 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

3 participants