Skip to content

Commit 08cbdb3

Browse files
[video_player] Updates min SDK to 3.29 (#9826)
For the `video_player` packages: - Updates the min SDK version to 3.29 - Runs the autoformatter with the new format - Update code excerpts This does not update versions because pushing format changes (even in READMEs) isn't worth doing a release that drops an SDK version (which we don't normally version) Prep for #9816
1 parent 40e6c7b commit 08cbdb3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1902
-1732
lines changed

packages/video_player/video_player/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## NEXT
2+
3+
* Updates minimum supported SDK version to Flutter 3.29/Dart 3.7.
4+
15
## 2.10.0
26

37
* Adds support for platform views as an optional way of displaying a video on Android and iOS.

packages/video_player/video_player/README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ class _VideoAppState extends State<VideoApp> {
7777
@override
7878
void initState() {
7979
super.initState();
80-
_controller = VideoPlayerController.networkUrl(Uri.parse(
81-
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4'))
80+
_controller = VideoPlayerController.networkUrl(
81+
Uri.parse(
82+
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4',
83+
),
84+
)
8285
..initialize().then((_) {
8386
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
8487
setState(() {});
@@ -91,12 +94,13 @@ class _VideoAppState extends State<VideoApp> {
9194
title: 'Video Demo',
9295
home: Scaffold(
9396
body: Center(
94-
child: _controller.value.isInitialized
95-
? AspectRatio(
96-
aspectRatio: _controller.value.aspectRatio,
97-
child: VideoPlayer(_controller),
98-
)
99-
: Container(),
97+
child:
98+
_controller.value.isInitialized
99+
? AspectRatio(
100+
aspectRatio: _controller.value.aspectRatio,
101+
child: VideoPlayer(_controller),
102+
)
103+
: Container(),
100104
),
101105
floatingActionButton: FloatingActionButton(
102106
onPressed: () {
@@ -120,6 +124,7 @@ class _VideoAppState extends State<VideoApp> {
120124
super.dispose();
121125
}
122126
}
127+
123128
```
124129

125130
## Usage

packages/video_player/video_player/example/integration_test/controller_swap_test.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ void main() {
6262
await another.pause();
6363

6464
// Expect that `another` played.
65-
expect(another.value.position,
66-
(Duration position) => position > Duration.zero);
65+
expect(
66+
another.value.position,
67+
(Duration position) => position > Duration.zero,
68+
);
6769

6870
await expectLater(started.future, completes);
6971
await expectLater(ended.future, completes);
@@ -75,12 +77,9 @@ void main() {
7577

7678
// TODO(tarrinneal): Remove once other test is enabled,
7779
// https://github.com/flutter/flutter/issues/164651
78-
testWidgets(
79-
'no-op',
80-
(WidgetTester tester) async {
81-
expect(true, true);
82-
},
83-
);
80+
testWidgets('no-op', (WidgetTester tester) async {
81+
expect(true, true);
82+
});
8483
}
8584

8685
Widget renderVideoWidget(VideoPlayerController controller) {

packages/video_player/video_player/example/integration_test/video_player_test.dart

Lines changed: 115 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)