@@ -49,77 +49,71 @@ void main() {
49
49
expect (controller.value.position, Duration .zero);
50
50
expect (controller.value.isPlaying, false );
51
51
// 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
+ );
54
56
});
55
57
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 ();
65
66
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 );
74
75
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 );
82
81
83
- await controller.play ();
84
- await tester.pumpAndSettle (_playDuration);
82
+ await controller.play ();
83
+ await tester.pumpAndSettle (_playDuration);
85
84
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
+ });
91
91
92
- testWidgets (
93
- 'can seek' ,
94
- (WidgetTester tester) async {
95
- await controller.initialize ();
92
+ testWidgets ('can seek' , (WidgetTester tester) async {
93
+ await controller.initialize ();
96
94
97
- await controller.seekTo (const Duration (seconds: 3 ));
95
+ await controller.seekTo (const Duration (seconds: 3 ));
98
96
99
- expect (controller.value.position, const Duration (seconds: 3 ));
100
- },
101
- );
97
+ expect (controller.value.position, const Duration (seconds: 3 ));
98
+ });
102
99
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 );
110
105
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);
117
112
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
+ });
123
117
124
118
testWidgets (
125
119
'stay paused when seeking after video completed' ,
@@ -142,7 +136,8 @@ void main() {
142
136
// https://github.com/flutter/flutter/issues/141145 is fixed.
143
137
if ((! kIsWeb && Platform .isAndroid) && controller.value.isPlaying) {
144
138
markTestSkipped (
145
- 'Skipping due to https://github.com/flutter/flutter/issues/141145' );
139
+ 'Skipping due to https://github.com/flutter/flutter/issues/141145' ,
140
+ );
146
141
return ;
147
142
}
148
143
expect (controller.value.isPlaying, false );
@@ -166,7 +161,8 @@ void main() {
166
161
// See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
167
162
await controller.setVolume (0 );
168
163
await controller.seekTo (
169
- controller.value.duration - const Duration (milliseconds: 10 ));
164
+ controller.value.duration - const Duration (milliseconds: 10 ),
165
+ );
170
166
await controller.play ();
171
167
await tester.pumpAndSettle (_playDuration);
172
168
// Android emulators in our CI have frequent flake where the video
@@ -178,7 +174,8 @@ void main() {
178
174
// https://github.com/flutter/flutter/issues/141145 is fixed.
179
175
if ((! kIsWeb && Platform .isAndroid) && controller.value.isPlaying) {
180
176
markTestSkipped (
181
- 'Skipping due to https://github.com/flutter/flutter/issues/141145' );
177
+ 'Skipping due to https://github.com/flutter/flutter/issues/141145' ,
178
+ );
182
179
return ;
183
180
}
184
181
expect (controller.value.isPlaying, false );
@@ -187,52 +184,61 @@ void main() {
187
184
await controller.play ();
188
185
await tester.pumpAndSettle (_playDuration);
189
186
190
- expect (controller.value.position,
191
- lessThanOrEqualTo (controller.value.duration));
187
+ expect (
188
+ controller.value.position,
189
+ lessThanOrEqualTo (controller.value.duration),
190
+ );
192
191
},
193
192
// Flaky on the web, headless browsers don't like to seek to non-buffered
194
193
// positions of a video (and since this isn't even injecting the video
195
194
// element on the page, the video never starts buffering with the test)
196
195
skip: kIsWeb,
197
196
);
198
197
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
+ ),
225
231
),
226
232
),
227
- ),
228
- ));
233
+ );
229
234
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
+ );
236
242
});
237
243
238
244
group ('file-based videos' , () {
@@ -249,8 +255,9 @@ void main() {
249
255
controller = VideoPlayerController .file (file);
250
256
});
251
257
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 {
254
261
await controller.initialize ();
255
262
256
263
await controller.play ();
@@ -264,7 +271,8 @@ void main() {
264
271
group ('network videos' , () {
265
272
setUp (() {
266
273
controller = VideoPlayerController .networkUrl (
267
- Uri .parse (getUrlForAssetAsNetworkSource (_videoAssetKey)));
274
+ Uri .parse (getUrlForAssetAsNetworkSource (_videoAssetKey)),
275
+ );
268
276
});
269
277
270
278
testWidgets (
@@ -293,17 +301,19 @@ void main() {
293
301
await controller.pause ();
294
302
295
303
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
+ );
298
308
299
309
await expectLater (started.future, completes);
300
310
await expectLater (ended.future, completes);
301
311
},
302
312
skip:
303
313
// MEDIA_ELEMENT_ERROR on web, see https://github.com/flutter/flutter/issues/169219
304
314
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,
307
317
);
308
318
});
309
319
0 commit comments