Skip to content

Commit b290ae0

Browse files
authored
[video_player_platform_interface] Add preventsDisplaySleepDuringVideoPlayback option (#11546)
## 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 - Parent PR: #11225 - Fixes: flutter/flutter#183520
1 parent 06ed8de commit b290ae0

4 files changed

Lines changed: 27 additions & 2 deletions

File tree

packages/video_player/video_player_platform_interface/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
## NEXT
1+
## 6.8.0
22

3+
* Adds `preventsDisplaySleepDuringVideoPlayback` to `VideoPlayerOptions` and
4+
`setPreventsDisplaySleepDuringVideoPlayback` to `VideoPlayerPlatform`. The
5+
default implementation is a no-op so platforms that do not support
6+
controlling display sleep silently fall back to their default behavior.
37
* Updates minimum supported SDK version to Flutter 3.38/Dart 3.10.
48

59
## 6.7.0

packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ abstract class VideoPlayerPlatform extends PlatformInterface {
122122
throw UnimplementedError('setAllowBackgroundPlayback() has not been implemented.');
123123
}
124124

125+
/// Sets whether the screen is prevented from sleeping during video playback.
126+
///
127+
/// The default implementation is a no-op, so platforms that do not support
128+
/// controlling display sleep will silently use their default behavior.
129+
Future<void> setPreventsDisplaySleepDuringVideoPlayback(
130+
int playerId,
131+
bool preventsDisplaySleepDuringVideoPlayback,
132+
) async {}
133+
125134
/// Sets additional options on web.
126135
Future<void> setWebOptions(int playerId, VideoPlayerWebOptions options) {
127136
throw UnimplementedError('setWebOptions() has not been implemented.');
@@ -461,6 +470,7 @@ class VideoPlayerOptions {
461470
VideoPlayerOptions({
462471
this.mixWithOthers = false,
463472
this.allowBackgroundPlayback = false,
473+
this.preventsDisplaySleepDuringVideoPlayback = true,
464474
this.webOptions,
465475
});
466476

@@ -475,6 +485,13 @@ class VideoPlayerOptions {
475485
/// currently no way to implement this feature in this platform).
476486
final bool mixWithOthers;
477487

488+
/// Whether the screen is prevented from sleeping during video playback.
489+
///
490+
/// Defaults to `true`.
491+
///
492+
/// This option may not be supported on all platforms.
493+
final bool preventsDisplaySleepDuringVideoPlayback;
494+
478495
/// Additional web controls
479496
final VideoPlayerWebOptions? webOptions;
480497
}

packages/video_player/video_player_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/video_player/
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 6.7.0
7+
version: 6.8.0
88

99
environment:
1010
sdk: ^3.10.0

packages/video_player/video_player_platform_interface/test/video_player_options_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ void main() {
1414
final options = VideoPlayerOptions();
1515
expect(options.mixWithOthers, false);
1616
});
17+
test('VideoPlayerOptions preventsDisplaySleepDuringVideoPlayback defaults to true', () {
18+
final options = VideoPlayerOptions();
19+
expect(options.preventsDisplaySleepDuringVideoPlayback, true);
20+
});
1721
}

0 commit comments

Comments
 (0)