Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions packages/video_player/video_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
16 changes: 15 additions & 1 deletion packages/video_player/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -436,6 +442,14 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
_creatingCompleter!.complete(null);
final Completer<void> initializingCompleter = Completer<void>();

// Apply the web-specific options
if (kIsWeb && videoPlayerOptions?.webOptions != null) {
await _videoPlayerPlatform.setWebOptions(
_textureId,
videoPlayerOptions!.webOptions!,
);
}

void eventListener(VideoEvent event) {
if (_isDisposed) {
return;
Expand Down
4 changes: 2 additions & 2 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, 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"
Expand All @@ -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 <7.0.0"
video_player_web: ^2.0.0

dev_dependencies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,59 @@
// 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';

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);
}
12 changes: 12 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 @@ -1311,6 +1311,8 @@ class FakeVideoPlayerPlatform extends VideoPlayerPlatform {
bool forceInitError = false;
int nextTextureId = 0;
final Map<int, Duration> _positions = <int, Duration>{};
final Map<int, VideoPlayerWebOptions> webOptions =
<int, VideoPlayerWebOptions>{};

@override
Future<int?> create(DataSource dataSource) async {
Expand Down Expand Up @@ -1392,4 +1394,14 @@ class FakeVideoPlayerPlatform extends VideoPlayerPlatform {
Widget buildView(int textureId) {
return Texture(textureId: textureId);
}

@override
Future<void> setWebOptions(
int textureId, VideoPlayerWebOptions options) async {
if (!kIsWeb) {
throw UnimplementedError('setWebOptions() is only available in the web.');
}
calls.add('setWebOptions');
webOptions[textureId] = options;
}
}