Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## NEXT
## 6.7.0

* Adds `preventsDisplaySleepDuringVideoPlayback` to `VideoPlayerOptions` and
`setPreventsDisplaySleepDuringVideoPlayback` to `VideoPlayerPlatform`.
Comment thread
tarrinneal marked this conversation as resolved.
* Updates minimum supported SDK version to Flutter 3.35/Dart 3.9.

## 6.6.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ abstract class VideoPlayerPlatform extends PlatformInterface {
);
}

/// Sets whether the screen is prevented from sleeping during video playback.
Future<void> setPreventsDisplaySleepDuringVideoPlayback(
int playerId,
bool preventsDisplaySleepDuringVideoPlayback,
) {
throw UnimplementedError(
'setPreventsDisplaySleepDuringVideoPlayback() has not been implemented.',
);
}
Comment on lines +128 to +135
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.',
);
}


/// Sets additional options on web.
Future<void> setWebOptions(int playerId, VideoPlayerWebOptions options) {
throw UnimplementedError('setWebOptions() has not been implemented.');
Expand Down Expand Up @@ -435,6 +445,7 @@ class VideoPlayerOptions {
VideoPlayerOptions({
this.mixWithOthers = false,
this.allowBackgroundPlayback = false,
this.preventsDisplaySleepDuringVideoPlayback = true,
this.webOptions,
});

Expand All @@ -449,6 +460,13 @@ class VideoPlayerOptions {
/// currently no way to implement this feature in this platform).
final bool mixWithOthers;

/// Whether the screen is prevented from sleeping during video playback.
///
/// Defaults to `true`.
///
/// This option is currently only supported on iOS and macOS.
final bool preventsDisplaySleepDuringVideoPlayback;

/// Additional web controls
final VideoPlayerWebOptions? webOptions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/video_player/
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
# 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.7.0

environment:
sdk: ^3.9.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@ void main() {
final options = VideoPlayerOptions();
expect(options.mixWithOthers, false);
});
test(
'VideoPlayerOptions preventsDisplaySleepDuringVideoPlayback defaults to true',
() {
final options = VideoPlayerOptions();
expect(options.preventsDisplaySleepDuringVideoPlayback, true);
},
);
}