diff --git a/packages/video_player/video_player/CHANGELOG.md b/packages/video_player/video_player/CHANGELOG.md index 7de2bc64061..91b9f02c057 100644 --- a/packages/video_player/video_player/CHANGELOG.md +++ b/packages/video_player/video_player/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.9.0 + +* Exports types: `VideoPlayerWebOptions` and `VideoPlayerWebOptionsControls` to + customize the `webOptions` field in `VideoPlayerOptions` objects. +* Forwards `webOptions` to the web implementation. + ## 2.8.7 * Ensures that `value.position` never reports a value larger than `value.duration`. diff --git a/packages/video_player/video_player/lib/video_player.dart b/packages/video_player/video_player/lib/video_player.dart index 4d7f68e7272..c8acd6e969b 100644 --- a/packages/video_player/video_player/lib/video_player.dart +++ b/packages/video_player/video_player/lib/video_player.dart @@ -14,7 +14,13 @@ import 'package:video_player_platform_interface/video_player_platform_interface. import 'src/closed_caption_file.dart'; export 'package:video_player_platform_interface/video_player_platform_interface.dart' - show DataSourceType, DurationRange, VideoFormat, VideoPlayerOptions; + show + DataSourceType, + DurationRange, + VideoFormat, + VideoPlayerOptions, + VideoPlayerWebOptions, + VideoPlayerWebOptionsControls; export 'src/closed_caption_file.dart'; @@ -436,6 +442,14 @@ class VideoPlayerController extends ValueNotifier { _creatingCompleter!.complete(null); final Completer initializingCompleter = Completer(); + // Apply the web-specific options + if (kIsWeb && videoPlayerOptions?.webOptions != null) { + await _videoPlayerPlatform.setWebOptions( + _textureId, + videoPlayerOptions!.webOptions!, + ); + } + void eventListener(VideoEvent event) { if (_isDisposed) { return; diff --git a/packages/video_player/video_player/pubspec.yaml b/packages/video_player/video_player/pubspec.yaml index 9ed1b6f7e29..aff4a9700c7 100644 --- a/packages/video_player/video_player/pubspec.yaml +++ b/packages/video_player/video_player/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for displaying inline video with other Flutter widgets on Android, iOS, 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.8.7 +version: 2.9.0 environment: sdk: ">=3.2.3 <4.0.0" @@ -27,7 +27,7 @@ dependencies: html: ^0.15.0 video_player_android: ^2.3.5 video_player_avfoundation: ^2.5.6 - video_player_platform_interface: ">=6.1.0 <7.0.0" + video_player_platform_interface: ^6.2.0 video_player_web: ^2.0.0 dev_dependencies: diff --git a/packages/video_player/video_player/test/video_player_initialization_test.dart b/packages/video_player/video_player/test/video_player_initialization_test.dart index 38cf71f67e8..5ecc7e4d69b 100644 --- a/packages/video_player/video_player/test/video_player_initialization_test.dart +++ b/packages/video_player/video_player/test/video_player_initialization_test.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:video_player/video_player.dart'; import 'package:video_player_platform_interface/video_player_platform_interface.dart'; @@ -9,18 +10,51 @@ import 'package:video_player_platform_interface/video_player_platform_interface. import 'video_player_test.dart' show FakeVideoPlayerPlatform; void main() { - // This test needs to run first and therefore needs to be the only test - // in this file. - test('plugin initialized', () async { - TestWidgetsFlutterBinding.ensureInitialized(); - final FakeVideoPlayerPlatform fakeVideoPlayerPlatform = - FakeVideoPlayerPlatform(); - VideoPlayerPlatform.instance = fakeVideoPlayerPlatform; + TestWidgetsFlutterBinding.ensureInitialized(); + + late FakeVideoPlayerPlatform fakeVideoPlayerPlatform; + + setUp(() { + VideoPlayerPlatform.instance = + fakeVideoPlayerPlatform = FakeVideoPlayerPlatform(); + }); + test('plugin initialized', () async { final VideoPlayerController controller = VideoPlayerController.networkUrl( Uri.parse('https://127.0.0.1'), ); await controller.initialize(); expect(fakeVideoPlayerPlatform.calls.first, 'init'); }); + + test('web configuration is applied (web only)', () async { + const VideoPlayerWebOptions expected = VideoPlayerWebOptions( + allowContextMenu: false, + allowRemotePlayback: false, + controls: VideoPlayerWebOptionsControls.enabled(), + ); + + final VideoPlayerController controller = VideoPlayerController.networkUrl( + Uri.parse('https://127.0.0.1'), + videoPlayerOptions: VideoPlayerOptions( + webOptions: expected, + ), + ); + await controller.initialize(); + + expect( + () { + fakeVideoPlayerPlatform.calls.singleWhere( + (String call) => call == 'setWebOptions', + ); + }, + returnsNormally, + reason: 'setWebOptions must be called exactly once.', + ); + expect( + fakeVideoPlayerPlatform.webOptions[controller.textureId], + expected, + reason: 'web options must be passed to the platform', + ); + }, skip: !kIsWeb); } diff --git a/packages/video_player/video_player/test/video_player_test.dart b/packages/video_player/video_player/test/video_player_test.dart index c62615a06e4..f6eef244811 100644 --- a/packages/video_player/video_player/test/video_player_test.dart +++ b/packages/video_player/video_player/test/video_player_test.dart @@ -1311,6 +1311,8 @@ class FakeVideoPlayerPlatform extends VideoPlayerPlatform { bool forceInitError = false; int nextTextureId = 0; final Map _positions = {}; + final Map webOptions = + {}; @override Future create(DataSource dataSource) async { @@ -1392,4 +1394,14 @@ class FakeVideoPlayerPlatform extends VideoPlayerPlatform { Widget buildView(int textureId) { return Texture(textureId: textureId); } + + @override + Future setWebOptions( + int textureId, VideoPlayerWebOptions options) async { + if (!kIsWeb) { + throw UnimplementedError('setWebOptions() is only available in the web.'); + } + calls.add('setWebOptions'); + webOptions[textureId] = options; + } }