Skip to content
Closed
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
Expand Up @@ -91,6 +91,32 @@ void main() {
},
);

testWidgets(
'can go fullscreen',
(WidgetTester tester) async {
await controller.initialize();
// Mute to allow playing without DOM interaction on Web.
// See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
await controller.setVolume(0);

await controller.play();
await controller.toggleFullScreen();
await tester.pumpAndSettle(_playDuration);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you have to play a second of video for full screen changes to take effect?


expect(controller.value.isFullScreen, true);
expect(controller.value.position,
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is this expectation related to the functionality you are testing?

(Duration position) => position > Duration.zero);

await controller.toggleFullScreen();
await tester.pumpAndSettle(_playDuration);

expect(controller.value.isFullScreen, false);
expect(controller.value.position,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same question here.

(Duration position) => position > Duration.zero);
},
skip: !kIsWeb,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather than making this platform-gated, there should be a supportsFullScreen API at both the app-facing and platform interface levels so that it's runtime-checkable.

);

testWidgets(
'can seek',
(WidgetTester tester) async {
Expand Down
3 changes: 3 additions & 0 deletions packages/video_player/video_player/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ class _ControlsOverlay extends StatelessWidget {
onTap: () {
controller.value.isPlaying ? controller.pause() : controller.play();
},
onDoubleTap: () {
controller.toggleFullScreen();
},
),
Align(
alignment: Alignment.topLeft,
Expand Down
7 changes: 7 additions & 0 deletions packages/video_player/video_player/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ flutter:
- assets/bumble_bee_captions.srt
- assets/bumble_bee_captions.vtt
- assets/Audio.mp3

# FOR TESTING ONLY. DO NOT MERGE.
dependency_overrides:
video_player_platform_interface:
path: ../../../video_player/video_player_platform_interface
video_player_web:
path: ../../../video_player/video_player_web
33 changes: 33 additions & 0 deletions packages/video_player/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class VideoPlayerValue {
this.isPlaying = false,
this.isLooping = false,
this.isBuffering = false,
this.isFullScreen = false,
this.volume = 1.0,
this.playbackSpeed = 1.0,
this.rotationCorrection = 0,
Expand Down Expand Up @@ -93,6 +94,9 @@ class VideoPlayerValue {
/// True if the video is playing. False if it's paused.
final bool isPlaying;

/// True if the video is in fullscreen. False if it's not.
final bool isFullScreen;

/// True if the video is looping.
final bool isLooping;

Expand Down Expand Up @@ -151,6 +155,7 @@ class VideoPlayerValue {
List<DurationRange>? buffered,
bool? isInitialized,
bool? isPlaying,
bool? isFullScreen,
bool? isLooping,
bool? isBuffering,
double? volume,
Expand All @@ -167,6 +172,7 @@ class VideoPlayerValue {
buffered: buffered ?? this.buffered,
isInitialized: isInitialized ?? this.isInitialized,
isPlaying: isPlaying ?? this.isPlaying,
isFullScreen: isFullScreen ?? this.isFullScreen,
isLooping: isLooping ?? this.isLooping,
isBuffering: isBuffering ?? this.isBuffering,
volume: volume ?? this.volume,
Expand Down Expand Up @@ -475,6 +481,19 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
await _applyPlayPause();
}

/// The video enters in fullscreen (only works for Web).
Future<void> toggleFullScreen() async {
if (kIsWeb) {
if (!value.isFullScreen) {
await _applyFullScreen();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since these are only used in one place, they don't need to be separated out into helpers.

value = value.copyWith(isFullScreen: true);
} else {
await _applyExitFullScreen();
value = value.copyWith(isFullScreen: false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can't the user exit full screen directly? It seems like we would need a state listener for this, rather than managing the state from Dart.

}
}
}

Future<void> _applyLooping() async {
if (_isDisposedOrNotInitialized) {
return;
Expand Down Expand Up @@ -522,6 +541,20 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
await _videoPlayerPlatform.setVolume(_textureId, value.volume);
}

Future<void> _applyFullScreen() async {
if (!kIsWeb || _isDisposedOrNotInitialized) {
return;
}
await _videoPlayerPlatform.enterFullScreen(_textureId);
}

Future<void> _applyExitFullScreen() async {
if (!kIsWeb || _isDisposedOrNotInitialized) {
return;
}
await _videoPlayerPlatform.exitFullScreen(_textureId);
}

Future<void> _applyPlaybackSpeed() async {
if (_isDisposedOrNotInitialized) {
return;
Expand Down
8 changes: 8 additions & 0 deletions packages/video_player/video_player/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter


# FOR TESTING ONLY. DO NOT MERGE.
dependency_overrides:
video_player_platform_interface:
path: ../../video_player/video_player_platform_interface
video_player_web:
path: ../../video_player/video_player_web
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class FakeController extends ValueNotifier<VideoPlayerValue>
Future<void> setClosedCaptionFile(
Future<ClosedCaptionFile>? closedCaptionFile,
) async {}

@override
Future<void> toggleFullScreen() async {}
}

Future<ClosedCaptionFile> _loadClosedCaption() async =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ flutter:
assets:
- assets/flutter-mark-square-64.png
- assets/Butterfly-209.mp4


# FOR TESTING ONLY. DO NOT MERGE.
dependency_overrides:
video_player_platform_interface:
path: ../../../video_player/video_player_platform_interface
6 changes: 6 additions & 0 deletions packages/video_player/video_player_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ dev_dependencies:
flutter_test:
sdk: flutter
pigeon: ^2.0.1


# FOR TESTING ONLY. DO NOT MERGE.
dependency_overrides:
video_player_platform_interface:
path: ../../video_player/video_player_platform_interface
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ flutter:
assets:
- assets/flutter-mark-square-64.png
- assets/Butterfly-209.mp4


# FOR TESTING ONLY. DO NOT MERGE.
dependency_overrides:
video_player_platform_interface:
path: ../../../video_player/video_player_platform_interface
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ dev_dependencies:
flutter_test:
sdk: flutter
pigeon: ^8.0.0


# FOR TESTING ONLY. DO NOT MERGE.
dependency_overrides:
video_player_platform_interface:
path: ../../video_player/video_player_platform_interface
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 6.2.0

* Adds fullscreen functionality (only for web-platform).

## 6.1.0

* Aligns Dart and Flutter SDK constraints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ abstract class VideoPlayerPlatform extends PlatformInterface {
throw UnimplementedError('pause() has not been implemented.');
}

/// The video enters fullScreen (only available for web platform).
Future<void> enterFullScreen(int textureId) {
throw UnimplementedError('enterFullScreen() has not been implemented.');
}

/// The video exits fullScreen (only available for web platform).
Future<void> exitFullScreen(int textureId) {
throw UnimplementedError('exitFullScreen() has not been implemented.');
}

/// Sets the volume to a range between 0.0 and 1.0.
Future<void> setVolume(int textureId, double volume) {
throw UnimplementedError('setVolume() has not been implemented.');
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.1.0
version: 6.2.0

environment:
sdk: ">=2.17.0 <4.0.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/video_player/video_player_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.1.0

* Adds fullscreen functionality (only for web-platform).

## 2.0.15

* Clarifies explanation of endorsement in README.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ void main() {
expect(VideoPlayerPlatform.instance.pause(await textureId), completes);
});

testWidgets('can enter fullscreen', (WidgetTester tester) async {
expect(VideoPlayerPlatform.instance.enterFullScreen(await textureId),
completes);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is only testing that the future completes, not that it does anything. Wouldn't at empty implementation of enterFullScreen pass this test?

});

testWidgets('can exit fullscreen', (WidgetTester tester) async {
expect(VideoPlayerPlatform.instance.exitFullScreen(await textureId),
completes);
});

testWidgets('can set volume', (WidgetTester tester) async {
expect(
VideoPlayerPlatform.instance.setVolume(await textureId, 0.8),
Expand Down
8 changes: 8 additions & 0 deletions packages/video_player/video_player_web/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ dev_dependencies:
sdk: flutter
integration_test:
sdk: flutter


# FOR TESTING ONLY. DO NOT MERGE.
dependency_overrides:
video_player_platform_interface:
path: ../../../video_player/video_player_platform_interface
video_player_web:
path: ../../../video_player/video_player_web
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ class VideoPlayer {
_videoElement.pause();
}

/// The video enters in fullScreen (only available for web platform).
void enterFullscreen() {
_videoElement.enterFullscreen();
}

/// The video exits fullScreen (only available for web platform).
void exitFullscreen() {
_videoElement.exitFullscreen();
}

/// Controls whether the video should start again after it finishes.
// ignore: use_setters_to_change_properties
void setLooping(bool value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ class VideoPlayerPlugin extends VideoPlayerPlatform {
return _player(textureId).pause();
}

@override
Future<void> enterFullScreen(int textureId) async {
return _player(textureId).enterFullscreen();
}

@override
Future<void> exitFullScreen(int textureId) async {
return _player(textureId).exitFullscreen();
}

@override
Future<void> setVolume(int textureId, double volume) async {
return _player(textureId).setVolume(volume);
Expand Down
8 changes: 7 additions & 1 deletion packages/video_player/video_player_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: video_player_web
description: Web platform implementation of video_player.
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
version: 2.0.15
version: 2.1.0

environment:
sdk: ">=2.17.0 <4.0.0"
Expand All @@ -26,3 +26,9 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter


# FOR TESTING ONLY. DO NOT MERGE.
dependency_overrides:
video_player_platform_interface:
path: ../../video_player/video_player_platform_interface