Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
fed4658
Implement screen auto-lock control for video playback
shrabanti722 Mar 9, 2026
f688bdb
Refactor VideoPlayerController to streamline player initialization
shrabanti722 Mar 9, 2026
3c60307
PR prep: format, fix pubspec sort, update changelog and versions
shrabanti722 Mar 11, 2026
46ea3e9
Update changelogs to reflect the implementation of screen auto-lock c…
shrabanti722 Mar 11, 2026
74b02a4
Merge upstream/main into video-player-screen-auto-lock
shrabanti722 Mar 11, 2026
dffa3a4
Add allowScreenAutoLock default value test
shrabanti722 Mar 11, 2026
742e1b5
Update dependency overrides in pubspec.yaml files for video_player pa…
shrabanti722 Mar 12, 2026
263bdc5
Update packages/video_player/video_player_avfoundation/darwin/video_p…
shrabanti722 Mar 14, 2026
04f9b57
Update packages/video_player/video_player/lib/video_player.dart
shrabanti722 Mar 14, 2026
15d7d64
Update packages/video_player/video_player_platform_interface/lib/vide…
shrabanti722 Mar 14, 2026
b30287e
refactor: Update Pigeon and refine API for preventing display sleep d…
shrabanti722 Mar 20, 2026
2b353a9
deleted test output file
shrabanti722 Mar 20, 2026
da08c54
feat: Add `preventsDisplaySleepDuringVideoPlayback` option to control…
shrabanti722 Mar 21, 2026
6353082
style: reformat AVFoundation video player code and generated Pigeon m…
shrabanti722 Mar 21, 2026
1e1f173
updating versions
shrabanti722 Apr 4, 2026
5a42c83
chore: downgrade video_player_platform_interface dependency versions …
shrabanti722 Apr 7, 2026
0bd9c68
chore: downgrade video_player_platform_interface version to 6.6.0 in …
shrabanti722 Apr 8, 2026
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
7 changes: 7 additions & 0 deletions packages/video_player/video_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 2.12.0

* Adds `preventsDisplaySleepDuringVideoPlayback` to `VideoPlayerOptions` and
`VideoPlayerValue`, and `setPreventsDisplaySleepDuringVideoPlayback` to
`VideoPlayerController`, to control whether the display sleeps during playback
on iOS and macOS.

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

This will need to be a new entry in the changelog along with a version bump to 2.12.0


* Optimizes caption retrieval with binary search.
Expand Down
5 changes: 5 additions & 0 deletions packages/video_player/video_player/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ flutter:
- assets/bumble_bee_captions.srt
- assets/bumble_bee_captions.vtt
- assets/Audio.mp3
# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
video_player_avfoundation: {path: ../../../../packages/video_player/video_player_avfoundation}
video_player_platform_interface: {path: ../../../../packages/video_player/video_player_platform_interface}
93 changes: 86 additions & 7 deletions packages/video_player/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class VideoPlayerValue {
this.rotationCorrection = 0,
this.errorDescription,
this.isCompleted = false,
this.preventsDisplaySleepDuringVideoPlayback = true,
});

/// Returns an instance for a video that hasn't been loaded.
Expand Down Expand Up @@ -239,6 +240,13 @@ class VideoPlayerValue {
/// Does not update if video is looping.
final bool isCompleted;

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

/// The [size] of the currently loaded video.
final Size size;

Expand Down Expand Up @@ -287,6 +295,7 @@ class VideoPlayerValue {
int? rotationCorrection,
String? errorDescription = _defaultErrorDescription,
bool? isCompleted,
bool? preventsDisplaySleepDuringVideoPlayback,
}) {
return VideoPlayerValue(
duration: duration ?? this.duration,
Expand All @@ -306,6 +315,9 @@ class VideoPlayerValue {
? errorDescription
: this.errorDescription,
isCompleted: isCompleted ?? this.isCompleted,
preventsDisplaySleepDuringVideoPlayback:
preventsDisplaySleepDuringVideoPlayback ??
this.preventsDisplaySleepDuringVideoPlayback,
);
}

Expand All @@ -325,7 +337,8 @@ class VideoPlayerValue {
'volume: $volume, '
'playbackSpeed: $playbackSpeed, '
'errorDescription: $errorDescription, '
'isCompleted: $isCompleted),';
'isCompleted: $isCompleted, '
'preventsDisplaySleepDuringVideoPlayback: $preventsDisplaySleepDuringVideoPlayback),';
}

@override
Expand All @@ -347,7 +360,9 @@ class VideoPlayerValue {
size == other.size &&
rotationCorrection == other.rotationCorrection &&
isInitialized == other.isInitialized &&
isCompleted == other.isCompleted;
isCompleted == other.isCompleted &&
preventsDisplaySleepDuringVideoPlayback ==
other.preventsDisplaySleepDuringVideoPlayback;

@override
int get hashCode => Object.hash(
Expand All @@ -366,6 +381,7 @@ class VideoPlayerValue {
rotationCorrection,
isInitialized,
isCompleted,
preventsDisplaySleepDuringVideoPlayback,
);
}

Expand Down Expand Up @@ -399,7 +415,14 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
dataSourceType = platform_interface.DataSourceType.asset,
formatHint = null,
httpHeaders = const <String, String>{},
super(const VideoPlayerValue(duration: Duration.zero));
super(
VideoPlayerValue(
duration: Duration.zero,
preventsDisplaySleepDuringVideoPlayback:
videoPlayerOptions?.preventsDisplaySleepDuringVideoPlayback ??
true,
),
);

/// Constructs a [VideoPlayerController] playing a network video.
///
Expand All @@ -425,7 +448,14 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
}) : _closedCaptionFileFuture = closedCaptionFile,
dataSourceType = platform_interface.DataSourceType.network,
package = null,
super(const VideoPlayerValue(duration: Duration.zero));
super(
VideoPlayerValue(
duration: Duration.zero,
preventsDisplaySleepDuringVideoPlayback:
videoPlayerOptions?.preventsDisplaySleepDuringVideoPlayback ??
true,
),
);

/// Constructs a [VideoPlayerController] playing a network video.
///
Expand All @@ -447,7 +477,14 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
dataSource = url.toString(),
dataSourceType = platform_interface.DataSourceType.network,
package = null,
super(const VideoPlayerValue(duration: Duration.zero));
super(
VideoPlayerValue(
duration: Duration.zero,
preventsDisplaySleepDuringVideoPlayback:
videoPlayerOptions?.preventsDisplaySleepDuringVideoPlayback ??
true,
),
);

/// Constructs a [VideoPlayerController] playing a video from a file.
///
Expand All @@ -464,7 +501,14 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
dataSourceType = platform_interface.DataSourceType.file,
package = null,
formatHint = null,
super(const VideoPlayerValue(duration: Duration.zero));
super(
VideoPlayerValue(
duration: Duration.zero,
preventsDisplaySleepDuringVideoPlayback:
videoPlayerOptions?.preventsDisplaySleepDuringVideoPlayback ??
true,
),
);

/// Constructs a [VideoPlayerController] playing a video from a contentUri.
///
Expand All @@ -485,7 +529,14 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
package = null,
formatHint = null,
httpHeaders = const <String, String>{},
super(const VideoPlayerValue(duration: Duration.zero));
super(
VideoPlayerValue(
duration: Duration.zero,
preventsDisplaySleepDuringVideoPlayback:
videoPlayerOptions?.preventsDisplaySleepDuringVideoPlayback ??
true,
),
);

/// The URI to the video file. This will be in different formats depending on
/// the [DataSourceType] of the original video.
Expand Down Expand Up @@ -590,6 +641,11 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
_creatingCompleter!.complete(null);
final initializingCompleter = Completer<void>();

await _videoPlayerPlatform.setPreventsDisplaySleepDuringVideoPlayback(
_playerId,
value.preventsDisplaySleepDuringVideoPlayback,
);

// Apply the web-specific options
if (kIsWeb && videoPlayerOptions?.webOptions != null) {
await _videoPlayerPlatform.setWebOptions(
Expand Down Expand Up @@ -715,6 +771,19 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
await _applyLooping();
}

/// Sets whether the screen is prevented from sleeping during video playback.
///
/// See also [VideoPlayerValue.preventsDisplaySleepDuringVideoPlayback].
Future<void> setPreventsDisplaySleepDuringVideoPlayback(
bool preventsDisplaySleepDuringVideoPlayback,
) async {
value = value.copyWith(
preventsDisplaySleepDuringVideoPlayback:
preventsDisplaySleepDuringVideoPlayback,
);
await _applyPreventsDisplaySleepDuringVideoPlayback();
}

/// Pauses the video.
Future<void> pause() async {
value = value.copyWith(isPlaying: false);
Expand All @@ -728,6 +797,16 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
await _videoPlayerPlatform.setLooping(_playerId, value.isLooping);
}

Future<void> _applyPreventsDisplaySleepDuringVideoPlayback() async {
if (_isDisposedOrNotInitialized) {
return;
}
await _videoPlayerPlatform.setPreventsDisplaySleepDuringVideoPlayback(
_playerId,
value.preventsDisplaySleepDuringVideoPlayback,
);
}

Future<void> _applyPlayPause() async {
if (_isDisposedOrNotInitialized) {
return;
Expand Down
9 changes: 7 additions & 2 deletions packages/video_player/video_player/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for displaying inline video with other Flutter
widgets on Android, iOS, macOS and web.
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
version: 2.11.1
version: 2.12.0

environment:
sdk: ^3.10.0
Expand All @@ -27,7 +27,7 @@ dependencies:
sdk: flutter
html: ^0.15.0
video_player_android: ^2.9.1
video_player_avfoundation: ^2.9.0
video_player_avfoundation: ^2.10.0
video_player_platform_interface: ^6.6.0
video_player_web: ^2.1.0

Expand All @@ -39,3 +39,8 @@ dev_dependencies:
topics:
- video
- video-player
# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
video_player_avfoundation: {path: ../../../packages/video_player/video_player_avfoundation}
video_player_platform_interface: {path: ../../../packages/video_player/video_player_platform_interface}
34 changes: 33 additions & 1 deletion packages/video_player/video_player/test/video_player_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ class FakeController extends ValueNotifier<VideoPlayerValue>
@override
Future<void> setLooping(bool looping) async {}

@override
Future<void> setPreventsDisplaySleepDuringVideoPlayback(
bool prevents,
) async {}

@override
VideoFormat? get formatHint => null;

Expand Down Expand Up @@ -1858,7 +1863,8 @@ void main() {
'volume: 0.5, '
'playbackSpeed: 1.5, '
'errorDescription: null, '
'isCompleted: false),',
'isCompleted: false, '
'preventsDisplaySleepDuringVideoPlayback: true),',
);
});

Expand Down Expand Up @@ -1954,6 +1960,24 @@ void main() {
expect(controller.videoPlayerOptions!.mixWithOthers, true);
});

test('setPreventsDisplaySleepDuringVideoPlayback', () async {
final controller = VideoPlayerController.networkUrl(_localhostUri);
addTearDown(controller.dispose);

await controller.initialize();
expect(controller.value.preventsDisplaySleepDuringVideoPlayback, true);

await controller.setPreventsDisplaySleepDuringVideoPlayback(false);
expect(controller.value.preventsDisplaySleepDuringVideoPlayback, false);

expect(
fakeVideoPlayerPlatform.calls.contains(
'setPreventsDisplaySleepDuringVideoPlayback',
),
true,
);
});

test('true allowBackgroundPlayback continues playback', () async {
final controller = VideoPlayerController.networkUrl(
_localhostUri,
Expand Down Expand Up @@ -2227,6 +2251,14 @@ class FakeVideoPlayerPlatform extends VideoPlayerPlatform {
calls.add('setMixWithOthers');
}

@override
Future<void> setPreventsDisplaySleepDuringVideoPlayback(
int playerId,
bool preventsDisplaySleepDuringVideoPlayback,
) async {
calls.add('setPreventsDisplaySleepDuringVideoPlayback');
}

@override
Widget buildView(int playerId) {
return Texture(textureId: playerId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ flutter:
assets:
- assets/flutter-mark-square-64.png
- assets/Butterfly-209.mp4
# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
video_player_platform_interface: {path: ../../../../packages/video_player/video_player_platform_interface}
4 changes: 4 additions & 0 deletions packages/video_player/video_player_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ dev_dependencies:
topics:
- video
- video-player
# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
video_player_platform_interface: {path: ../../../packages/video_player/video_player_platform_interface}
5 changes: 5 additions & 0 deletions packages/video_player/video_player_avfoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.10.0

* Implements `setPreventsDisplaySleepDuringVideoPlayback` using
`AVPlayer.preventsDisplaySleepDuringVideoPlayback`.

## 2.9.4

* Ensures that the display link does not continue requesting frames after a player is disposed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,12 @@ - (void)selectAudioTrackAtIndex:(NSInteger)trackIndex
}
}

- (void)setPreventsDisplaySleepDuringVideoPlayback:(BOOL)preventsDisplaySleepDuringVideoPlayback error:(FlutterError *_Nullable *_Nonnull)error {
if (@available(iOS 12.0, macOS 10.14, *)) {
self.player.preventsDisplaySleepDuringVideoPlayback = preventsDisplaySleepDuringVideoPlayback;
}
}

#pragma mark - Private

- (int64_t)duration {
Expand Down
Loading