Skip to content
Open
Show file tree
Hide file tree
Changes from 10 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
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

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

## 2.11.0
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}
11 changes: 9 additions & 2 deletions packages/video_player/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,15 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
_playerId =
(await _videoPlayerPlatform.createWithOptions(creationOptions)) ??
kUninitializedPlayerId;
_creatingCompleter!.complete(null);
final initializingCompleter = Completer<void>();
if (videoPlayerOptions != null) {
await _videoPlayerPlatform.setAllowScreenAutoLock(
_playerId,
videoPlayerOptions.allowScreenAutoLock,
);
}
videoPlayerOptions!.allowScreenAutoLock,
);
}

// Apply the web-specific options
if (kIsWeb && videoPlayerOptions?.webOptions != null) {
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the repository style guide, temporary dependency_overrides should be accompanied by a comment to prevent them from being merged. Please add the comment # FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. before the dependency_overrides: block.

References
  1. The repository style guide states that temporary dependency_overrides sections in pubspec.yaml files should include a comment starting with 'FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.' to prevent accidental merging. This override is missing the required comment. (link)

# 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}

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
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}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.9.5

* Implement screen auto-lock control for video playback.
Copy link
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, macOS 10.14, *)) {
self.player.preventsDisplaySleepDuringVideoPlayback = !allowScreenAutoLock;
Copy link
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.

}
}

#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 @@ -31,3 +31,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}
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);
}
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,9 @@ 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:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the repository style guide, temporary dependency_overrides should be accompanied by a comment to prevent them from being merged. Please add the comment # FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. before the dependency_overrides: block.

References
  1. The repository style guide states that temporary dependency_overrides sections in pubspec.yaml files should include a comment starting with 'FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.' to prevent accidental merging. This override is missing the required comment. (link)

video_player_platform_interface: {path: ../../../packages/video_player/video_player_platform_interface}

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 6.6.1

* 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 and macOS.
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

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);
});
}
4 changes: 4 additions & 0 deletions packages/video_player/video_player_web/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ dev_dependencies:
sdk: flutter
integration_test:
sdk: flutter
# 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_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,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}