2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
-
6
5
// TODO(amirh): Remove this once flutter_driver supports null safety.
7
6
// https://github.com/flutter/flutter/issues/71379
8
7
// @dart = 2.9
8
+ import 'dart:async' ;
9
9
10
+ import 'package:flutter/foundation.dart' ;
10
11
import 'package:flutter/material.dart' ;
11
12
import 'package:integration_test/integration_test.dart' ;
12
13
import 'package:flutter_test/flutter_test.dart' ;
@@ -34,10 +35,58 @@ void main() {
34
35
const Duration (seconds: 7 , milliseconds: 540 ));
35
36
});
36
37
38
+ testWidgets (
39
+ 'reports buffering status' ,
40
+ (WidgetTester tester) async {
41
+ VideoPlayerController networkController = VideoPlayerController .network (
42
+ 'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4' ,
43
+ );
44
+ await networkController.initialize ();
45
+ // Mute to allow playing without DOM interaction on Web.
46
+ // See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
47
+ await networkController.setVolume (0 );
48
+ final Completer <void > started = Completer ();
49
+ final Completer <void > ended = Completer ();
50
+ bool startedBuffering = false ;
51
+ bool endedBuffering = false ;
52
+ networkController.addListener (() {
53
+ if (networkController.value.isBuffering && ! startedBuffering) {
54
+ startedBuffering = true ;
55
+ started.complete ();
56
+ }
57
+ if (startedBuffering &&
58
+ ! networkController.value.isBuffering &&
59
+ ! endedBuffering) {
60
+ endedBuffering = true ;
61
+ ended.complete ();
62
+ }
63
+ });
64
+
65
+ await networkController.play ();
66
+ await networkController.seekTo (const Duration (seconds: 5 ));
67
+ await tester.pumpAndSettle (_playDuration);
68
+ await networkController.pause ();
69
+
70
+ expect (networkController.value.isPlaying, false );
71
+ expect (networkController.value.position,
72
+ (Duration position) => position > const Duration (seconds: 0 ));
73
+
74
+ await started;
75
+ expect (startedBuffering, true );
76
+
77
+ await ended;
78
+ expect (endedBuffering, true );
79
+ },
80
+ skip: ! (kIsWeb || defaultTargetPlatform == TargetPlatform .android),
81
+ );
82
+
37
83
testWidgets (
38
84
'can be played' ,
39
85
(WidgetTester tester) async {
40
86
await _controller.initialize ();
87
+ // Mute to allow playing without DOM interaction on Web.
88
+ // See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
89
+ await _controller.setVolume (0 );
41
90
42
91
await _controller.play ();
43
92
await tester.pumpAndSettle (_playDuration);
@@ -63,6 +112,9 @@ void main() {
63
112
'can be paused' ,
64
113
(WidgetTester tester) async {
65
114
await _controller.initialize ();
115
+ // Mute to allow playing without DOM interaction on Web.
116
+ // See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
117
+ await _controller.setVolume (0 );
66
118
67
119
// Play for a second, then pause, and then wait a second.
68
120
await _controller.play ();
@@ -109,6 +161,6 @@ void main() {
109
161
110
162
await tester.pumpAndSettle ();
111
163
expect (_controller.value.isPlaying, true );
112
- });
164
+ }, skip : kIsWeb); // Web does not support local assets.
113
165
});
114
166
}
0 commit comments