Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
20 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
4839f96
Merge upstream/main; replace temporary dependency overrides with publ…
shrabanti722 Jul 10, 2026
75f86c6
Merge upstream/main; bump to 2.13.0 and reformat for Dart 3.12
shrabanti722 Jul 11, 2026
cdfc331
[video_player] Apply dart format fix for newer formatter
shrabanti722 Jul 13, 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
6 changes: 5 additions & 1 deletion packages/video_player/video_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## NEXT
## 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.
* Updates minimum supported SDK version to Flutter 3.38/Dart 3.10.

## 2.11.1
Comment thread
tarrinneal marked this conversation as resolved.
Expand Down
85 changes: 78 additions & 7 deletions packages/video_player/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,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 @@ -224,6 +225,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 @@ -272,6 +280,7 @@ class VideoPlayerValue {
int? rotationCorrection,
String? errorDescription = _defaultErrorDescription,
bool? isCompleted,
bool? preventsDisplaySleepDuringVideoPlayback,
}) {
return VideoPlayerValue(
duration: duration ?? this.duration,
Expand All @@ -291,6 +300,8 @@ class VideoPlayerValue {
? errorDescription
: this.errorDescription,
isCompleted: isCompleted ?? this.isCompleted,
preventsDisplaySleepDuringVideoPlayback:
preventsDisplaySleepDuringVideoPlayback ?? this.preventsDisplaySleepDuringVideoPlayback,
);
}

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

@override
Expand All @@ -332,7 +344,8 @@ 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 @@ -351,6 +364,7 @@ class VideoPlayerValue {
rotationCorrection,
isInitialized,
isCompleted,
preventsDisplaySleepDuringVideoPlayback,
);
}

Expand Down Expand Up @@ -384,7 +398,13 @@ 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 @@ -410,7 +430,13 @@ 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 @@ -432,7 +458,13 @@ 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 @@ -449,7 +481,13 @@ 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 @@ -470,7 +508,13 @@ 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 @@ -571,6 +615,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(_playerId, videoPlayerOptions!.webOptions!);
Expand Down Expand Up @@ -690,6 +739,18 @@ 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 @@ -703,6 +764,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
6 changes: 3 additions & 3 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,8 +27,8 @@ dependencies:
sdk: flutter
html: ^0.15.0
video_player_android: ^2.9.1
video_player_avfoundation: ^2.9.0
video_player_platform_interface: ^6.6.0
video_player_avfoundation: ^2.11.0
video_player_platform_interface: ^6.8.0
video_player_web: ^2.1.0

dev_dependencies:
Expand Down
42 changes: 34 additions & 8 deletions packages/video_player/video_player/test/video_player_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class FakeController extends ValueNotifier<VideoPlayerValue> implements VideoPla
@override
Future<void> setLooping(bool looping) async {}

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

@override
VideoFormat? get formatHint => null;

Expand Down Expand Up @@ -1027,13 +1030,11 @@ void main() {
}

expect(isSorted, false, reason: 'Expected captions to be unsorted');
expect(captions.map((Caption c) => c.text).toList(), <String>[
'one',
'two',
'three',
'five',
'four',
], reason: 'Captions should be in original unsorted order');
expect(
captions.map((Caption c) => c.text).toList(),
<String>['one', 'two', 'three', 'five', 'four'],
reason: 'Captions should be in original unsorted order',
);
});

test('works when seeking, includes all captions', () async {
Expand Down Expand Up @@ -1667,7 +1668,8 @@ void main() {
'volume: 0.5, '
'playbackSpeed: 1.5, '
'errorDescription: null, '
'isCompleted: false),',
'isCompleted: false, '
'preventsDisplaySleepDuringVideoPlayback: true),',
);
});

Expand Down Expand Up @@ -1754,6 +1756,22 @@ 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 @@ -2004,6 +2022,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