[video_player] Add a Uri-typed factory method (#3513)

This PR improves VideoPlayerController network constructor with the datasource type. The solution follows the comments on the issue [#121927](https://github.com/flutter/flutter/issues/121927).

Fixes [#121927](https://github.com/flutter/flutter/issues/121927)
This commit is contained in:
Gabriel Okura
2023-06-29 11:28:08 -03:00
committed by GitHub
parent a0ea9a3679
commit 5d6e48c3e0
15 changed files with 260 additions and 115 deletions

View File

@ -994,6 +994,10 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
} }
final VideoPlayerController vController = kIsWeb final VideoPlayerController vController = kIsWeb
// TODO(gabrielokura): remove the ignore once the following line can migrate to
// use VideoPlayerController.networkUrl after the issue is resolved.
// https://github.com/flutter/flutter/issues/121927
// ignore: deprecated_member_use
? VideoPlayerController.network(videoFile!.path) ? VideoPlayerController.network(videoFile!.path)
: VideoPlayerController.file(File(videoFile!.path)); : VideoPlayerController.file(File(videoFile!.path));

View File

@ -1002,6 +1002,10 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
} }
final VideoPlayerController vController = kIsWeb final VideoPlayerController vController = kIsWeb
// TODO(gabrielokura): remove the ignore once the following line can migrate to
// use VideoPlayerController.networkUrl after the issue is resolved.
// https://github.com/flutter/flutter/issues/121927
// ignore: deprecated_member_use
? VideoPlayerController.network(videoFile!.path) ? VideoPlayerController.network(videoFile!.path)
: VideoPlayerController.file(File(videoFile!.path)); : VideoPlayerController.file(File(videoFile!.path));

View File

@ -979,6 +979,10 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
} }
final VideoPlayerController vController = kIsWeb final VideoPlayerController vController = kIsWeb
// TODO(gabrielokura): remove the ignore once the following line can migrate to
// use VideoPlayerController.networkUrl after the issue is resolved.
// https://github.com/flutter/flutter/issues/121927
// ignore: deprecated_member_use
? VideoPlayerController.network(videoFile!.path) ? VideoPlayerController.network(videoFile!.path)
: VideoPlayerController.file(File(videoFile!.path)); : VideoPlayerController.file(File(videoFile!.path));

View File

@ -1002,6 +1002,10 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
} }
final VideoPlayerController vController = kIsWeb final VideoPlayerController vController = kIsWeb
// TODO(gabrielokura): remove the ignore once the following line can migrate to
// use VideoPlayerController.networkUrl after the issue is resolved.
// https://github.com/flutter/flutter/issues/121927
// ignore: deprecated_member_use
? VideoPlayerController.network(videoFile!.path) ? VideoPlayerController.network(videoFile!.path)
: VideoPlayerController.file(File(videoFile!.path)); : VideoPlayerController.file(File(videoFile!.path));

View File

@ -62,6 +62,10 @@ class _MyHomePageState extends State<MyHomePage> {
await _disposeVideoController(); await _disposeVideoController();
late VideoPlayerController controller; late VideoPlayerController controller;
if (kIsWeb) { if (kIsWeb) {
// TODO(gabrielokura): remove the ignore once the following line can migrate to
// use VideoPlayerController.networkUrl after the issue is resolved.
// https://github.com/flutter/flutter/issues/121927
// ignore: deprecated_member_use
controller = VideoPlayerController.network(file.path); controller = VideoPlayerController.network(file.path);
} else { } else {
controller = VideoPlayerController.file(File(file.path)); controller = VideoPlayerController.file(File(file.path));

View File

@ -65,4 +65,6 @@ Anton Borries <mail@antonborri.es>
Alex Li <google@alexv525.com> Alex Li <google@alexv525.com>
Rahul Raj <64.rahulraj@gmail.com> Rahul Raj <64.rahulraj@gmail.com>
Koen Van Looveren <vanlooverenkoen.dev@gmail.com> Koen Van Looveren <vanlooverenkoen.dev@gmail.com>
Gabriel Motelevicz Okura <gabriellevicz@gmail.com>
Idowu Tomiwa <tommydprogrammer@gmail.com>
Márton Matuz <matuzmarci@gmail.com> Márton Matuz <matuzmarci@gmail.com>

View File

@ -1,7 +1,9 @@
## NEXT ## 2.7.0
* Adds an `Uri` typed factory method `VideoPlayerController.networkUrl` to avoid common mistakes with `String` URIs. The method
receives an`Uri` instead of a `String` url.
* Deprecates `VideoPlayerController.network` factory method.
* Updates minimum supported SDK version to Flutter 3.3/Dart 2.18. * Updates minimum supported SDK version to Flutter 3.3/Dart 2.18.
## 2.6.1 ## 2.6.1
* Synchronizes `VideoPlayerValue.isPlaying` with underlying video player. * Synchronizes `VideoPlayerValue.isPlaying` with underlying video player.

View File

@ -73,8 +73,8 @@ class _VideoAppState extends State<VideoApp> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_controller = VideoPlayerController.network( _controller = VideoPlayerController.networkUrl(Uri.parse(
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4') 'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4'))
..initialize().then((_) { ..initialize().then((_) {
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed. // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
setState(() {}); setState(() {});

View File

@ -57,8 +57,9 @@ void main() {
'live stream duration != 0', 'live stream duration != 0',
(WidgetTester tester) async { (WidgetTester tester) async {
final VideoPlayerController networkController = final VideoPlayerController networkController =
VideoPlayerController.network( VideoPlayerController.networkUrl(
'https://flutter.github.io/assets-for-api-docs/assets/videos/hls/bee.m3u8', Uri.parse(
'https://flutter.github.io/assets-for-api-docs/assets/videos/hls/bee.m3u8'),
); );
await networkController.initialize(); await networkController.initialize();
@ -230,8 +231,8 @@ void main() {
group('network videos', () { group('network videos', () {
setUp(() { setUp(() {
controller = VideoPlayerController.network( controller = VideoPlayerController.networkUrl(
getUrlForAssetAsNetworkSource(_videoAssetKey)); Uri.parse(getUrlForAssetAsNetworkSource(_videoAssetKey)));
}); });
testWidgets( testWidgets(

View File

@ -27,8 +27,8 @@ class _VideoAppState extends State<VideoApp> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_controller = VideoPlayerController.network( _controller = VideoPlayerController.networkUrl(Uri.parse(
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4') 'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4'))
..initialize().then((_) { ..initialize().then((_) {
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed. // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
setState(() {}); setState(() {});

View File

@ -217,8 +217,9 @@ class _BumbleBeeRemoteVideoState extends State<_BumbleBeeRemoteVideo> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_controller = VideoPlayerController.network( _controller = VideoPlayerController.networkUrl(
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4', Uri.parse(
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4'),
closedCaptionFile: _loadCaptions(), closedCaptionFile: _loadCaptions(),
videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true), videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true),
); );

View File

@ -262,15 +262,16 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
httpHeaders = const <String, String>{}, httpHeaders = const <String, String>{},
super(const VideoPlayerValue(duration: Duration.zero)); super(const VideoPlayerValue(duration: Duration.zero));
/// Constructs a [VideoPlayerController] playing a video from obtained from /// Constructs a [VideoPlayerController] playing a network video.
/// the network. ///
/// The URI for the video is given by the [dataSource] argument.
/// ///
/// The URI for the video is given by the [dataSource] argument and must not be
/// null.
/// **Android only**: The [formatHint] option allows the caller to override /// **Android only**: The [formatHint] option allows the caller to override
/// the video format detection code. /// the video format detection code.
/// [httpHeaders] option allows to specify HTTP headers. ///
/// [httpHeaders] option allows to specify HTTP headers
/// for the request to the [dataSource]. /// for the request to the [dataSource].
@Deprecated('Use VideoPlayerController.networkUrl instead')
VideoPlayerController.network( VideoPlayerController.network(
this.dataSource, { this.dataSource, {
this.formatHint, this.formatHint,
@ -282,6 +283,27 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
package = null, package = null,
super(const VideoPlayerValue(duration: Duration.zero)); super(const VideoPlayerValue(duration: Duration.zero));
/// Constructs a [VideoPlayerController] playing a network video.
///
/// The URI for the video is given by the [dataSource] argument.
///
/// **Android only**: The [formatHint] option allows the caller to override
/// the video format detection code.
///
/// [httpHeaders] option allows to specify HTTP headers
/// for the request to the [dataSource].
VideoPlayerController.networkUrl(
Uri url, {
this.formatHint,
Future<ClosedCaptionFile>? closedCaptionFile,
this.videoPlayerOptions,
this.httpHeaders = const <String, String>{},
}) : _closedCaptionFileFuture = closedCaptionFile,
dataSource = url.toString(),
dataSourceType = DataSourceType.network,
package = null,
super(const VideoPlayerValue(duration: Duration.zero));
/// Constructs a [VideoPlayerController] playing a video from a file. /// Constructs a [VideoPlayerController] playing a video from a file.
/// ///
/// This will load the file from a file:// URI constructed from [file]'s path. /// This will load the file from a file:// URI constructed from [file]'s path.

View File

@ -3,7 +3,7 @@ description: Flutter plugin for displaying inline video with other Flutter
widgets on Android, iOS, and web. widgets on Android, iOS, and web.
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player 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 issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
version: 2.6.1 version: 2.7.0
environment: environment:
sdk: ">=2.18.0 <4.0.0" sdk: ">=2.18.0 <4.0.0"

View File

@ -17,8 +17,8 @@ void main() {
FakeVideoPlayerPlatform(); FakeVideoPlayerPlatform();
VideoPlayerPlatform.instance = fakeVideoPlayerPlatform; VideoPlayerPlatform.instance = fakeVideoPlayerPlatform;
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller = VideoPlayerController.networkUrl(
'https://127.0.0.1', Uri.parse('https://127.0.0.1'),
); );
await controller.initialize(); await controller.initialize();
expect(fakeVideoPlayerPlatform.calls.first, 'init'); expect(fakeVideoPlayerPlatform.calls.first, 'init');

View File

@ -14,6 +14,9 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:video_player/video_player.dart'; import 'package:video_player/video_player.dart';
import 'package:video_player_platform_interface/video_player_platform_interface.dart'; import 'package:video_player_platform_interface/video_player_platform_interface.dart';
const String _localhost = 'https://127.0.0.1';
final Uri _localhostUri = Uri.parse(_localhost);
class FakeController extends ValueNotifier<VideoPlayerValue> class FakeController extends ValueNotifier<VideoPlayerValue>
implements VideoPlayerController { implements VideoPlayerController {
FakeController() : super(const VideoPlayerValue(duration: Duration.zero)); FakeController() : super(const VideoPlayerValue(duration: Duration.zero));
@ -243,27 +246,7 @@ void main() {
}); });
group('VideoPlayerController', () { group('VideoPlayerController', () {
group('initialize', () { group('legacy initialize', () {
test('started app lifecycle observing', () async {
final VideoPlayerController controller = VideoPlayerController.network(
'https://127.0.0.1',
);
await controller.initialize();
await controller.play();
verifyPlayStateRespondsToLifecycle(controller,
shouldPlayInBackground: false);
});
test('asset', () async {
final VideoPlayerController controller = VideoPlayerController.asset(
'a.avi',
);
await controller.initialize();
expect(fakeVideoPlayerPlatform.dataSources[0].asset, 'a.avi');
expect(fakeVideoPlayerPlatform.dataSources[0].package, null);
});
test('network', () async { test('network', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller = VideoPlayerController.network(
'https://127.0.0.1', 'https://127.0.0.1',
@ -325,11 +308,99 @@ void main() {
<String, String>{'Authorization': 'Bearer token'}, <String, String>{'Authorization': 'Bearer token'},
); );
}); });
});
test('init errors', () async { group('initialize', () {
final VideoPlayerController controller = VideoPlayerController.network( test('started app lifecycle observing', () async {
'http://testing.com/invalid_url', final VideoPlayerController controller =
VideoPlayerController.networkUrl(
Uri.parse('https://127.0.0.1'),
); );
await controller.initialize();
await controller.play();
verifyPlayStateRespondsToLifecycle(controller,
shouldPlayInBackground: false);
});
test('asset', () async {
final VideoPlayerController controller = VideoPlayerController.asset(
'a.avi',
);
await controller.initialize();
expect(fakeVideoPlayerPlatform.dataSources[0].asset, 'a.avi');
expect(fakeVideoPlayerPlatform.dataSources[0].package, null);
});
test('network url', () async {
final VideoPlayerController controller =
VideoPlayerController.networkUrl(Uri.parse('https://127.0.0.1'));
await controller.initialize();
expect(
fakeVideoPlayerPlatform.dataSources[0].uri,
'https://127.0.0.1',
);
expect(
fakeVideoPlayerPlatform.dataSources[0].formatHint,
null,
);
expect(
fakeVideoPlayerPlatform.dataSources[0].httpHeaders,
<String, String>{},
);
});
test('network url with hint', () async {
final VideoPlayerController controller =
VideoPlayerController.networkUrl(
Uri.parse('https://127.0.0.1'),
formatHint: VideoFormat.dash,
);
await controller.initialize();
expect(
fakeVideoPlayerPlatform.dataSources[0].uri,
'https://127.0.0.1',
);
expect(
fakeVideoPlayerPlatform.dataSources[0].formatHint,
VideoFormat.dash,
);
expect(
fakeVideoPlayerPlatform.dataSources[0].httpHeaders,
<String, String>{},
);
});
test('network url with some headers', () async {
final VideoPlayerController controller =
VideoPlayerController.networkUrl(
Uri.parse('https://127.0.0.1'),
httpHeaders: <String, String>{'Authorization': 'Bearer token'},
);
await controller.initialize();
expect(
fakeVideoPlayerPlatform.dataSources[0].uri,
'https://127.0.0.1',
);
expect(
fakeVideoPlayerPlatform.dataSources[0].formatHint,
null,
);
expect(
fakeVideoPlayerPlatform.dataSources[0].httpHeaders,
<String, String>{'Authorization': 'Bearer token'},
);
});
test(
'when controller is initialized with invalid url it should throw VideoError',
() async {
final Uri invalidUrl = Uri.parse('http://testing.com/invalid_url');
final VideoPlayerController controller =
VideoPlayerController.networkUrl(invalidUrl);
late Object error; late Object error;
fakeVideoPlayerPlatform.forceInitError = true; fakeVideoPlayerPlatform.forceInitError = true;
@ -387,6 +458,20 @@ void main() {
await controller.initialize(); await controller.initialize();
expect(controller.value.hasError, equals(false)); expect(controller.value.hasError, equals(false));
}); });
test(
'given controller with error when initialization succeeds it should clear error',
() async {
final VideoPlayerController controller =
VideoPlayerController.networkUrl(_localhostUri);
fakeVideoPlayerPlatform.forceInitError = true;
await controller.initialize().catchError((dynamic e) {});
expect(controller.value.hasError, equals(true));
fakeVideoPlayerPlatform.forceInitError = false;
await controller.initialize();
expect(controller.value.hasError, equals(false));
});
}); });
test('contentUri', () async { test('contentUri', () async {
@ -398,9 +483,9 @@ void main() {
}); });
test('dispose', () async { test('dispose', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(_localhostUri);
);
expect( expect(
controller.textureId, VideoPlayerController.kUninitializedTextureId); controller.textureId, VideoPlayerController.kUninitializedTextureId);
expect(await controller.position, Duration.zero); expect(await controller.position, Duration.zero);
@ -413,9 +498,8 @@ void main() {
}); });
test('calling dispose() on disposed controller does not throw', () async { test('calling dispose() on disposed controller does not throw', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(_localhostUri);
);
await controller.initialize(); await controller.initialize();
await controller.dispose(); await controller.dispose();
@ -424,9 +508,9 @@ void main() {
}); });
test('play', () async { test('play', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(Uri.parse('https://127.0.0.1'));
);
await controller.initialize(); await controller.initialize();
expect(controller.value.isPlaying, isFalse); expect(controller.value.isPlaying, isFalse);
await controller.play(); await controller.play();
@ -443,9 +527,9 @@ void main() {
}); });
test('play before initialized does not call platform', () async { test('play before initialized does not call platform', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(_localhostUri);
);
expect(controller.value.isInitialized, isFalse); expect(controller.value.isInitialized, isFalse);
await controller.play(); await controller.play();
@ -454,9 +538,9 @@ void main() {
}); });
test('play restarts from beginning if video is at end', () async { test('play restarts from beginning if video is at end', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(_localhostUri);
);
await controller.initialize(); await controller.initialize();
const Duration nonzeroDuration = Duration(milliseconds: 100); const Duration nonzeroDuration = Duration(milliseconds: 100);
controller.value = controller.value.copyWith(duration: nonzeroDuration); controller.value = controller.value.copyWith(duration: nonzeroDuration);
@ -471,9 +555,9 @@ void main() {
}); });
test('setLooping', () async { test('setLooping', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(_localhostUri);
);
await controller.initialize(); await controller.initialize();
expect(controller.value.isLooping, isFalse); expect(controller.value.isLooping, isFalse);
await controller.setLooping(true); await controller.setLooping(true);
@ -482,9 +566,9 @@ void main() {
}); });
test('pause', () async { test('pause', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(_localhostUri);
);
await controller.initialize(); await controller.initialize();
await controller.play(); await controller.play();
expect(controller.value.isPlaying, isTrue); expect(controller.value.isPlaying, isTrue);
@ -497,9 +581,9 @@ void main() {
group('seekTo', () { group('seekTo', () {
test('works', () async { test('works', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(_localhostUri);
);
await controller.initialize(); await controller.initialize();
expect(await controller.position, Duration.zero); expect(await controller.position, Duration.zero);
@ -509,9 +593,9 @@ void main() {
}); });
test('before initialized does not call platform', () async { test('before initialized does not call platform', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(_localhostUri);
);
expect(controller.value.isInitialized, isFalse); expect(controller.value.isInitialized, isFalse);
await controller.seekTo(const Duration(milliseconds: 500)); await controller.seekTo(const Duration(milliseconds: 500));
@ -520,9 +604,9 @@ void main() {
}); });
test('clamps values that are too high or low', () async { test('clamps values that are too high or low', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(_localhostUri);
);
await controller.initialize(); await controller.initialize();
expect(await controller.position, Duration.zero); expect(await controller.position, Duration.zero);
@ -536,9 +620,9 @@ void main() {
group('setVolume', () { group('setVolume', () {
test('works', () async { test('works', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(_localhostUri);
);
await controller.initialize(); await controller.initialize();
expect(controller.value.volume, 1.0); expect(controller.value.volume, 1.0);
@ -549,9 +633,9 @@ void main() {
}); });
test('clamps values that are too high or low', () async { test('clamps values that are too high or low', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(_localhostUri);
);
await controller.initialize(); await controller.initialize();
expect(controller.value.volume, 1.0); expect(controller.value.volume, 1.0);
@ -565,9 +649,9 @@ void main() {
group('setPlaybackSpeed', () { group('setPlaybackSpeed', () {
test('works', () async { test('works', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(_localhostUri);
);
await controller.initialize(); await controller.initialize();
expect(controller.value.playbackSpeed, 1.0); expect(controller.value.playbackSpeed, 1.0);
@ -578,9 +662,9 @@ void main() {
}); });
test('rejects negative values', () async { test('rejects negative values', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(_localhostUri);
);
await controller.initialize(); await controller.initialize();
expect(controller.value.playbackSpeed, 1.0); expect(controller.value.playbackSpeed, 1.0);
@ -591,9 +675,9 @@ void main() {
group('scrubbing', () { group('scrubbing', () {
testWidgets('restarts on release if already playing', testWidgets('restarts on release if already playing',
(WidgetTester tester) async { (WidgetTester tester) async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(_localhostUri);
);
await controller.initialize(); await controller.initialize();
final VideoProgressIndicator progressWidget = final VideoProgressIndicator progressWidget =
VideoProgressIndicator(controller, allowScrubbing: true); VideoProgressIndicator(controller, allowScrubbing: true);
@ -618,9 +702,9 @@ void main() {
testWidgets('does not restart when dragging to end', testWidgets('does not restart when dragging to end',
(WidgetTester tester) async { (WidgetTester tester) async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(_localhostUri);
);
await controller.initialize(); await controller.initialize();
final VideoProgressIndicator progressWidget = final VideoProgressIndicator progressWidget =
VideoProgressIndicator(controller, allowScrubbing: true); VideoProgressIndicator(controller, allowScrubbing: true);
@ -644,8 +728,9 @@ void main() {
group('caption', () { group('caption', () {
test('works when seeking', () async { test('works when seeking', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(
_localhostUri,
closedCaptionFile: _loadClosedCaption(), closedCaptionFile: _loadClosedCaption(),
); );
@ -676,8 +761,9 @@ void main() {
}); });
test('works when seeking with captionOffset positive', () async { test('works when seeking with captionOffset positive', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(
_localhostUri,
closedCaptionFile: _loadClosedCaption(), closedCaptionFile: _loadClosedCaption(),
); );
@ -712,8 +798,9 @@ void main() {
}); });
test('works when seeking with captionOffset negative', () async { test('works when seeking with captionOffset negative', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(
_localhostUri,
closedCaptionFile: _loadClosedCaption(), closedCaptionFile: _loadClosedCaption(),
); );
@ -751,8 +838,9 @@ void main() {
}); });
test('setClosedCaptionFile loads caption file', () async { test('setClosedCaptionFile loads caption file', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(
_localhostUri,
); );
await controller.initialize(); await controller.initialize();
@ -766,8 +854,9 @@ void main() {
}); });
test('setClosedCaptionFile removes/changes caption file', () async { test('setClosedCaptionFile removes/changes caption file', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(
_localhostUri,
closedCaptionFile: _loadClosedCaption(), closedCaptionFile: _loadClosedCaption(),
); );
@ -784,9 +873,11 @@ void main() {
group('Platform callbacks', () { group('Platform callbacks', () {
testWidgets('playing completed', (WidgetTester tester) async { testWidgets('playing completed', (WidgetTester tester) async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(
_localhostUri,
); );
await controller.initialize(); await controller.initialize();
const Duration nonzeroDuration = Duration(milliseconds: 100); const Duration nonzeroDuration = Duration(milliseconds: 100);
controller.value = controller.value.copyWith(duration: nonzeroDuration); controller.value = controller.value.copyWith(duration: nonzeroDuration);
@ -806,7 +897,7 @@ void main() {
testWidgets('playback status', (WidgetTester tester) async { testWidgets('playback status', (WidgetTester tester) async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller = VideoPlayerController.network(
'https://127.0.0.1', 'https://.0.0.1',
); );
await controller.initialize(); await controller.initialize();
expect(controller.value.isPlaying, isFalse); expect(controller.value.isPlaying, isFalse);
@ -829,9 +920,11 @@ void main() {
}); });
testWidgets('buffering status', (WidgetTester tester) async { testWidgets('buffering status', (WidgetTester tester) async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller =
'https://127.0.0.1', VideoPlayerController.networkUrl(
_localhostUri,
); );
await controller.initialize(); await controller.initialize();
expect(controller.value.isBuffering, false); expect(controller.value.isBuffering, false);
expect(controller.value.buffered, isEmpty); expect(controller.value.buffered, isEmpty);
@ -1057,20 +1150,23 @@ void main() {
group('VideoPlayerOptions', () { group('VideoPlayerOptions', () {
test('setMixWithOthers', () async { test('setMixWithOthers', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller = VideoPlayerController.networkUrl(
'https://127.0.0.1', _localhostUri,
videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true)); videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true),
);
await controller.initialize(); await controller.initialize();
expect(controller.videoPlayerOptions!.mixWithOthers, true); expect(controller.videoPlayerOptions!.mixWithOthers, true);
}); });
test('true allowBackgroundPlayback continues playback', () async { test('true allowBackgroundPlayback continues playback', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller = VideoPlayerController.networkUrl(
'https://127.0.0.1', _localhostUri,
videoPlayerOptions: VideoPlayerOptions( videoPlayerOptions: VideoPlayerOptions(
allowBackgroundPlayback: true, allowBackgroundPlayback: true,
), ),
); );
await controller.initialize(); await controller.initialize();
await controller.play(); await controller.play();
verifyPlayStateRespondsToLifecycle( verifyPlayStateRespondsToLifecycle(
@ -1080,10 +1176,11 @@ void main() {
}); });
test('false allowBackgroundPlayback pauses playback', () async { test('false allowBackgroundPlayback pauses playback', () async {
final VideoPlayerController controller = VideoPlayerController.network( final VideoPlayerController controller = VideoPlayerController.networkUrl(
'https://127.0.0.1', _localhostUri,
videoPlayerOptions: VideoPlayerOptions(), videoPlayerOptions: VideoPlayerOptions(),
); );
await controller.initialize(); await controller.initialize();
await controller.play(); await controller.play();
verifyPlayStateRespondsToLifecycle( verifyPlayStateRespondsToLifecycle(