@@ -49,77 +49,71 @@ void main() {
4949 expect (controller.value.position, Duration .zero);
5050 expect (controller.value.isPlaying, false );
5151 // The WebM version has a slightly different duration than the MP4.
52- expect (controller.value.duration,
53- const Duration (seconds: 7 , milliseconds: kIsWeb ? 544 : 540 ));
52+ expect (
53+ controller.value.duration,
54+ const Duration (seconds: 7 , milliseconds: kIsWeb ? 544 : 540 ),
55+ );
5456 });
5557
56- testWidgets (
57- 'live stream duration != 0' ,
58- (WidgetTester tester) async {
59- final VideoPlayerController networkController =
60- VideoPlayerController .networkUrl (
61- Uri .parse (
62- 'https://flutter.github.io/assets-for-api-docs/assets/videos/hls/bee.m3u8' ),
63- );
64- await networkController.initialize ();
58+ testWidgets ('live stream duration != 0' , (WidgetTester tester) async {
59+ final VideoPlayerController
60+ networkController = VideoPlayerController .networkUrl (
61+ Uri .parse (
62+ 'https://flutter.github.io/assets-for-api-docs/assets/videos/hls/bee.m3u8' ,
63+ ),
64+ );
65+ await networkController.initialize ();
6566
66- expect (networkController.value.isInitialized, true );
67- // Live streams should have either a positive duration or C.TIME_UNSET if the duration is unknown
68- // See https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/Player.html#getDuration--
69- expect (networkController.value.duration,
70- ( Duration duration) => duration != Duration .zero);
71- } ,
72- skip : kIsWeb,
73- );
67+ expect (networkController.value.isInitialized, true );
68+ // Live streams should have either a positive duration or C.TIME_UNSET if the duration is unknown
69+ // See https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/Player.html#getDuration--
70+ expect (
71+ networkController.value.duration,
72+ ( Duration duration) => duration != Duration .zero ,
73+ );
74+ }, skip : kIsWeb );
7475
75- testWidgets (
76- 'can be played' ,
77- (WidgetTester tester) async {
78- await controller.initialize ();
79- // Mute to allow playing without DOM interaction on Web.
80- // See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
81- await controller.setVolume (0 );
76+ testWidgets ('can be played' , (WidgetTester tester) async {
77+ await controller.initialize ();
78+ // Mute to allow playing without DOM interaction on Web.
79+ // See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
80+ await controller.setVolume (0 );
8281
83- await controller.play ();
84- await tester.pumpAndSettle (_playDuration);
82+ await controller.play ();
83+ await tester.pumpAndSettle (_playDuration);
8584
86- expect (controller.value.isPlaying, true );
87- expect (controller.value.position,
88- (Duration position) => position > Duration .zero);
89- },
90- );
85+ expect (controller.value.isPlaying, true );
86+ expect (
87+ controller.value.position,
88+ (Duration position) => position > Duration .zero,
89+ );
90+ });
9191
92- testWidgets (
93- 'can seek' ,
94- (WidgetTester tester) async {
95- await controller.initialize ();
92+ testWidgets ('can seek' , (WidgetTester tester) async {
93+ await controller.initialize ();
9694
97- await controller.seekTo (const Duration (seconds: 3 ));
95+ await controller.seekTo (const Duration (seconds: 3 ));
9896
99- expect (controller.value.position, const Duration (seconds: 3 ));
100- },
101- );
97+ expect (controller.value.position, const Duration (seconds: 3 ));
98+ });
10299
103- testWidgets (
104- 'can be paused' ,
105- (WidgetTester tester) async {
106- await controller.initialize ();
107- // Mute to allow playing without DOM interaction on Web.
108- // See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
109- await controller.setVolume (0 );
100+ testWidgets ('can be paused' , (WidgetTester tester) async {
101+ await controller.initialize ();
102+ // Mute to allow playing without DOM interaction on Web.
103+ // See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
104+ await controller.setVolume (0 );
110105
111- // Play for a second, then pause, and then wait a second.
112- await controller.play ();
113- await tester.pumpAndSettle (_playDuration);
114- await controller.pause ();
115- final Duration pausedPosition = controller.value.position;
116- await tester.pumpAndSettle (_playDuration);
106+ // Play for a second, then pause, and then wait a second.
107+ await controller.play ();
108+ await tester.pumpAndSettle (_playDuration);
109+ await controller.pause ();
110+ final Duration pausedPosition = controller.value.position;
111+ await tester.pumpAndSettle (_playDuration);
117112
118- // Verify that we stopped playing after the pause.
119- expect (controller.value.isPlaying, false );
120- expect (controller.value.position, pausedPosition);
121- },
122- );
113+ // Verify that we stopped playing after the pause.
114+ expect (controller.value.isPlaying, false );
115+ expect (controller.value.position, pausedPosition);
116+ });
123117
124118 testWidgets (
125119 'stay paused when seeking after video completed' ,
@@ -142,7 +136,8 @@ void main() {
142136 // https://github.com/flutter/flutter/issues/141145 is fixed.
143137 if ((! kIsWeb && Platform .isAndroid) && controller.value.isPlaying) {
144138 markTestSkipped (
145- 'Skipping due to https://github.com/flutter/flutter/issues/141145' );
139+ 'Skipping due to https://github.com/flutter/flutter/issues/141145' ,
140+ );
146141 return ;
147142 }
148143 expect (controller.value.isPlaying, false );
@@ -166,7 +161,8 @@ void main() {
166161 // See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
167162 await controller.setVolume (0 );
168163 await controller.seekTo (
169- controller.value.duration - const Duration (milliseconds: 10 ));
164+ controller.value.duration - const Duration (milliseconds: 10 ),
165+ );
170166 await controller.play ();
171167 await tester.pumpAndSettle (_playDuration);
172168 // Android emulators in our CI have frequent flake where the video
@@ -178,7 +174,8 @@ void main() {
178174 // https://github.com/flutter/flutter/issues/141145 is fixed.
179175 if ((! kIsWeb && Platform .isAndroid) && controller.value.isPlaying) {
180176 markTestSkipped (
181- 'Skipping due to https://github.com/flutter/flutter/issues/141145' );
177+ 'Skipping due to https://github.com/flutter/flutter/issues/141145' ,
178+ );
182179 return ;
183180 }
184181 expect (controller.value.isPlaying, false );
@@ -187,52 +184,61 @@ void main() {
187184 await controller.play ();
188185 await tester.pumpAndSettle (_playDuration);
189186
190- expect (controller.value.position,
191- lessThanOrEqualTo (controller.value.duration));
187+ expect (
188+ controller.value.position,
189+ lessThanOrEqualTo (controller.value.duration),
190+ );
192191 },
193192 // Flaky on the web, headless browsers don't like to seek to non-buffered
194193 // positions of a video (and since this isn't even injecting the video
195194 // element on the page, the video never starts buffering with the test)
196195 skip: kIsWeb,
197196 );
198197
199- testWidgets ('test video player view with local asset' ,
200- (WidgetTester tester) async {
201- final Completer <void > loaded = Completer <void >();
202- Future <bool > started () async {
203- await controller.initialize ();
204- await controller.play ();
205- loaded.complete ();
206- return true ;
207- }
208-
209- await tester.pumpWidget (Material (
210- child: Directionality (
211- textDirection: TextDirection .ltr,
212- child: Center (
213- child: FutureBuilder <bool >(
214- future: started (),
215- builder: (BuildContext context, AsyncSnapshot <bool > snapshot) {
216- if (snapshot.data ?? false ) {
217- return AspectRatio (
218- aspectRatio: controller.value.aspectRatio,
219- child: VideoPlayer (controller),
220- );
221- } else {
222- return const Text ('waiting for video to load' );
223- }
224- },
198+ testWidgets (
199+ 'test video player view with local asset' ,
200+ (WidgetTester tester) async {
201+ final Completer <void > loaded = Completer <void >();
202+ Future <bool > started () async {
203+ await controller.initialize ();
204+ await controller.play ();
205+ loaded.complete ();
206+ return true ;
207+ }
208+
209+ await tester.pumpWidget (
210+ Material (
211+ child: Directionality (
212+ textDirection: TextDirection .ltr,
213+ child: Center (
214+ child: FutureBuilder <bool >(
215+ future: started (),
216+ builder: (
217+ BuildContext context,
218+ AsyncSnapshot <bool > snapshot,
219+ ) {
220+ if (snapshot.data ?? false ) {
221+ return AspectRatio (
222+ aspectRatio: controller.value.aspectRatio,
223+ child: VideoPlayer (controller),
224+ );
225+ } else {
226+ return const Text ('waiting for video to load' );
227+ }
228+ },
229+ ),
230+ ),
225231 ),
226232 ),
227- ),
228- ));
233+ );
229234
230- await loaded.future;
231- await tester.pumpAndSettle ();
232- expect (controller.value.isPlaying, true );
233- },
234- // Web does not support local assets.
235- skip: kIsWeb);
235+ await loaded.future;
236+ await tester.pumpAndSettle ();
237+ expect (controller.value.isPlaying, true );
238+ },
239+ // Web does not support local assets.
240+ skip: kIsWeb,
241+ );
236242 });
237243
238244 group ('file-based videos' , () {
@@ -249,8 +255,9 @@ void main() {
249255 controller = VideoPlayerController .file (file);
250256 });
251257
252- testWidgets ('test video player using static file() method as constructor' ,
253- (WidgetTester tester) async {
258+ testWidgets ('test video player using static file() method as constructor' , (
259+ WidgetTester tester,
260+ ) async {
254261 await controller.initialize ();
255262
256263 await controller.play ();
@@ -264,7 +271,8 @@ void main() {
264271 group ('network videos' , () {
265272 setUp (() {
266273 controller = VideoPlayerController .networkUrl (
267- Uri .parse (getUrlForAssetAsNetworkSource (_videoAssetKey)));
274+ Uri .parse (getUrlForAssetAsNetworkSource (_videoAssetKey)),
275+ );
268276 });
269277
270278 testWidgets (
@@ -293,17 +301,19 @@ void main() {
293301 await controller.pause ();
294302
295303 expect (controller.value.isPlaying, false );
296- expect (controller.value.position,
297- (Duration position) => position > Duration .zero);
304+ expect (
305+ controller.value.position,
306+ (Duration position) => position > Duration .zero,
307+ );
298308
299309 await expectLater (started.future, completes);
300310 await expectLater (ended.future, completes);
301311 },
302312 skip:
303313 // MEDIA_ELEMENT_ERROR on web, see https://github.com/flutter/flutter/issues/169219
304314 kIsWeb ||
305- // Hanging on Android, see https://github.com/flutter/flutter/issues/160797
306- defaultTargetPlatform == TargetPlatform .android,
315+ // Hanging on Android, see https://github.com/flutter/flutter/issues/160797
316+ defaultTargetPlatform == TargetPlatform .android,
307317 );
308318 });
309319
0 commit comments