Skip to content

Commit fbf1314

Browse files
committed
[video_player_platform_interface] Add preventsDisplaySleepDuringVideoPlayback 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 #11225. Made-with: Cursor
1 parent 3888c6f commit fbf1314

4 files changed

Lines changed: 27 additions & 3 deletions

File tree

packages/video_player/video_player_platform_interface/CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
## NEXT
1+
## 6.7.0
22

3-
* Updates minimum supported SDK version to Flutter 3.35/Dart 3.9.
3+
* Adds `preventsDisplaySleepDuringVideoPlayback` to `VideoPlayerOptions` and
4+
`setPreventsDisplaySleepDuringVideoPlayback` to `VideoPlayerPlatform`.
45

56
## 6.6.0
67

packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ abstract class VideoPlayerPlatform extends PlatformInterface {
124124
);
125125
}
126126

127+
/// Sets whether the screen is prevented from sleeping during video playback.
128+
Future<void> setPreventsDisplaySleepDuringVideoPlayback(
129+
int playerId,
130+
bool preventsDisplaySleepDuringVideoPlayback,
131+
) {
132+
return Future<void>.value();
133+
}
134+
127135
/// Sets additional options on web.
128136
Future<void> setWebOptions(int playerId, VideoPlayerWebOptions options) {
129137
throw UnimplementedError('setWebOptions() has not been implemented.');
@@ -435,6 +443,7 @@ class VideoPlayerOptions {
435443
VideoPlayerOptions({
436444
this.mixWithOthers = false,
437445
this.allowBackgroundPlayback = false,
446+
this.preventsDisplaySleepDuringVideoPlayback = true,
438447
this.webOptions,
439448
});
440449

@@ -449,6 +458,13 @@ class VideoPlayerOptions {
449458
/// currently no way to implement this feature in this platform).
450459
final bool mixWithOthers;
451460

461+
/// Whether the screen is prevented from sleeping during video playback.
462+
///
463+
/// Defaults to `true`.
464+
///
465+
/// This option is currently only supported on iOS and macOS.
466+
final bool preventsDisplaySleepDuringVideoPlayback;
467+
452468
/// Additional web controls
453469
final VideoPlayerWebOptions? webOptions;
454470
}

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.6.0
7+
version: 6.7.0
88

99
environment:
1010
sdk: ^3.9.0

packages/video_player/video_player_platform_interface/test/video_player_options_test.dart

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

0 commit comments

Comments
 (0)