Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions packages/video_player/video_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 2.11.1
Comment thread
tarrinneal marked this conversation as resolved.

* Implement screen auto-lock control for video playback.
* Optimizes caption retrieval with binary search.

## 2.11.0
Expand Down
7 changes: 7 additions & 0 deletions packages/video_player/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,13 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
_creatingCompleter!.complete(null);
final initializingCompleter = Completer<void>();

if (videoPlayerOptions?.allowScreenAutoLock != null) {
await _videoPlayerPlatform.setAllowScreenAutoLock(
_playerId,
Comment thread
shrabanti722 marked this conversation as resolved.
Outdated
videoPlayerOptions!.allowScreenAutoLock,
);
}

// Apply the web-specific options
if (kIsWeb && videoPlayerOptions?.webOptions != null) {
await _videoPlayerPlatform.setWebOptions(
Expand Down
7 changes: 7 additions & 0 deletions packages/video_player/video_player/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@ dev_dependencies:
topics:
- video
- video-player

Comment thread
tarrinneal marked this conversation as resolved.
Outdated
dependency_overrides:
video_player_avfoundation:
path: ../video_player_avfoundation
video_player_platform_interface:
path: ../video_player_platform_interface

23 changes: 23 additions & 0 deletions packages/video_player/video_player/test/video_player_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1954,6 +1954,21 @@ void main() {
expect(controller.videoPlayerOptions!.mixWithOthers, true);
});

test('setAllowScreenAutoLock', () async {
final controller = VideoPlayerController.networkUrl(
_localhostUri,
videoPlayerOptions: VideoPlayerOptions(allowScreenAutoLock: true),
);
addTearDown(controller.dispose);

await controller.initialize();
expect(controller.videoPlayerOptions!.allowScreenAutoLock, true);
expect(
fakeVideoPlayerPlatform.calls.contains('setAllowScreenAutoLock'),
true,
);
});

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

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

@override
Widget buildView(int playerId) {
return Texture(textureId: playerId);
Expand Down
4 changes: 4 additions & 0 deletions packages/video_player/video_player_avfoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.9.5

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.

2.10.0


* Implement screen auto-lock control for video playback.

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.

Implements


## 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)setAllowScreenAutoLock:(BOOL)allowScreenAutoLock error:(FlutterError *_Nullable *_Nonnull)error {
if (@available(iOS 12.0, *)) {
self.player.preventsDisplaySleepDuringVideoPlayback = !allowScreenAutoLock;

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.

ScreenAutoLock sounds like screen orientation lock... Apple's preventsDisplaySleepDuringVideoPlayback is a good name, or something similar.

}
Comment thread
shrabanti722 marked this conversation as resolved.
Outdated
}

#pragma mark - Private

- (int64_t)duration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ extern void SetUpFVPAVFoundationVideoPlayerApiWithSuffix(
(FlutterError *_Nullable *_Nonnull)error;
- (void)selectAudioTrackAtIndex:(NSInteger)trackIndex
error:(FlutterError *_Nullable *_Nonnull)error;
- (void)setAllowScreenAutoLock:(BOOL)allowScreenAutoLock error:(FlutterError *_Nullable *_Nonnull)error;
@end

extern void SetUpFVPVideoPlayerInstanceApi(id<FlutterBinaryMessenger> binaryMessenger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,4 +591,28 @@ void SetUpFVPVideoPlayerInstanceApiWithSuffix(id<FlutterBinaryMessenger> binaryM
[channel setMessageHandler:nil];
}
}
{
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
initWithName:[NSString stringWithFormat:@"%@%@",
@"dev.flutter.pigeon.video_player_avfoundation."
@"VideoPlayerInstanceApi.setAllowScreenAutoLock",
messageChannelSuffix]
binaryMessenger:binaryMessenger
codec:FVPGetMessagesCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(setAllowScreenAutoLock:error:)],
@"FVPVideoPlayerInstanceApi api (%@) doesn't respond to "
@"@selector(setAllowScreenAutoLock:error:)",
api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
NSArray<id> *args = message;
BOOL arg_allowScreenAutoLock = [GetNullableObjectAtIndex(args, 0) boolValue];
FlutterError *error;
[api setAllowScreenAutoLock:arg_allowScreenAutoLock error:&error];
callback(wrapResult(nil, error));
}];
} else {
[channel setMessageHandler:nil];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ class AVFoundationVideoPlayer extends VideoPlayerPlatform {
return _api.setMixWithOthers(mixWithOthers);
}

@override
Future<void> setAllowScreenAutoLock(int playerId, bool allowScreenAutoLock) {
return _playerWith(
id: playerId,
).setAllowScreenAutoLock(allowScreenAutoLock);
}

@override
Future<List<VideoAudioTrack>> getAudioTracks(int playerId) async {
final List<MediaSelectionAudioTrackData> nativeData = await _playerWith(
Expand Down Expand Up @@ -275,6 +282,9 @@ class _PlayerInstance {

Future<void> setPlaybackSpeed(double speed) => _api.setPlaybackSpeed(speed);

Future<void> setAllowScreenAutoLock(bool allowScreenAutoLock) =>
_api.setAllowScreenAutoLock(allowScreenAutoLock);

Future<void> seekTo(Duration position) {
return _api.seekTo(position.inMilliseconds);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,4 +678,29 @@ class VideoPlayerInstanceApi {
return;
}
}

Future<void> setAllowScreenAutoLock(bool allowScreenAutoLock) async {
final pigeonVar_channelName =
'dev.flutter.pigeon.video_player_avfoundation.VideoPlayerInstanceApi.setAllowScreenAutoLock$pigeonVar_messageChannelSuffix';
final pigeonVar_channel = BasicMessageChannel<Object?>(
pigeonVar_channelName,
pigeonChannelCodec,
binaryMessenger: pigeonVar_binaryMessenger,
);
final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(
<Object?>[allowScreenAutoLock],
);
final pigeonVar_replyList = await pigeonVar_sendFuture as List<Object?>?;
if (pigeonVar_replyList == null) {
throw _createConnectionError(pigeonVar_channelName);
} else if (pigeonVar_replyList.length > 1) {
throw PlatformException(
code: pigeonVar_replyList[0]! as String,
message: pigeonVar_replyList[1] as String?,
details: pigeonVar_replyList[2],
);
} else {
return;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,6 @@ abstract class VideoPlayerInstanceApi {
List<MediaSelectionAudioTrackData> getAudioTracks();
@ObjCSelector('selectAudioTrackAtIndex:')
void selectAudioTrack(int trackIndex);
@ObjCSelector('setAllowScreenAutoLock:')
void setAllowScreenAutoLock(bool allowScreenAutoLock);
}
7 changes: 6 additions & 1 deletion packages/video_player/video_player_avfoundation/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: video_player_avfoundation
description: iOS and macOS implementation of the video_player plugin.
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player_avfoundation
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
version: 2.9.4
version: 2.9.5

environment:
sdk: ^3.10.0
Expand Down Expand Up @@ -36,3 +36,8 @@ dev_dependencies:
topics:
- video
- video-player

dependency_overrides:
Comment thread
tarrinneal marked this conversation as resolved.
Outdated
video_player_platform_interface:
path: ../video_player_platform_interface

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 6.6.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.

6.7.0


* Implement screen auto-lock control for video playback.
* 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,13 @@ abstract class VideoPlayerPlatform extends PlatformInterface {
);
}

/// Sets whether the screen should be allowed to auto-lock during playback.
Future<void> setAllowScreenAutoLock(int playerId, bool allowScreenAutoLock) {
throw UnimplementedError(
'setAllowScreenAutoLock() 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 +442,7 @@ class VideoPlayerOptions {
VideoPlayerOptions({
this.mixWithOthers = false,
this.allowBackgroundPlayback = false,
this.allowScreenAutoLock = false,
this.webOptions,
});

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

/// Set this to true to allow the screen to auto-lock during video playback.
/// The default value is false, meaning the screen will stay awake during playback.
///
/// This option is currently only supported on iOS.
Comment thread
shrabanti722 marked this conversation as resolved.
Outdated
final bool allowScreenAutoLock;

/// 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.6.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.

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,8 @@ void main() {
final options = VideoPlayerOptions();
expect(options.mixWithOthers, false);
});
test('VideoPlayerOptions allowScreenAutoLock defaults to false', () {
final options = VideoPlayerOptions();
expect(options.allowScreenAutoLock, false);
});
}