Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 6f037b4

Browse files
authored
[video_player] Ensure seekTo is not called before video player is initialized. (#4300)
1 parent 5d1ed48 commit 6f037b4

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

packages/video_player/video_player/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 2.1.15
22

3+
* Ensured seekTo isn't called before video player is initialized. Fixes [#89259](https://github.com/flutter/flutter/issues/89259).
34
* Updated Android lint settings.
45

56
## 2.1.14

packages/video_player/video_player/lib/video_player.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,14 +415,14 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
415415
}
416416

417417
Future<void> _applyLooping() async {
418-
if (!value.isInitialized || _isDisposed) {
418+
if (_isDisposedOrNotInitialized) {
419419
return;
420420
}
421421
await _videoPlayerPlatform.setLooping(_textureId, value.isLooping);
422422
}
423423

424424
Future<void> _applyPlayPause() async {
425-
if (!value.isInitialized || _isDisposed) {
425+
if (_isDisposedOrNotInitialized) {
426426
return;
427427
}
428428
if (value.isPlaying) {
@@ -455,14 +455,14 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
455455
}
456456

457457
Future<void> _applyVolume() async {
458-
if (!value.isInitialized || _isDisposed) {
458+
if (_isDisposedOrNotInitialized) {
459459
return;
460460
}
461461
await _videoPlayerPlatform.setVolume(_textureId, value.volume);
462462
}
463463

464464
Future<void> _applyPlaybackSpeed() async {
465-
if (!value.isInitialized || _isDisposed) {
465+
if (_isDisposedOrNotInitialized) {
466466
return;
467467
}
468468

@@ -491,7 +491,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
491491
/// If [moment] is outside of the video's full range it will be automatically
492492
/// and silently clamped.
493493
Future<void> seekTo(Duration position) async {
494-
if (_isDisposed) {
494+
if (_isDisposedOrNotInitialized) {
495495
return;
496496
}
497497
if (position > value.duration) {
@@ -572,6 +572,8 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
572572
value = value.copyWith(position: position);
573573
value = value.copyWith(caption: _getCaptionAt(position));
574574
}
575+
576+
bool get _isDisposedOrNotInitialized => _isDisposed || !value.isInitialized;
575577
}
576578

577579
class _VideoAppLifeCycleObserver extends Object with WidgetsBindingObserver {

packages/video_player/video_player/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for displaying inline video with other Flutter
33
widgets on Android, iOS, and web.
44
repository: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
6-
version: 2.1.14
6+
version: 2.1.15
77

88
environment:
99
sdk: ">=2.12.0 <3.0.0"

packages/video_player/video_player/test/video_player_test.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,17 @@ void main() {
318318
expect(fakeVideoPlayerPlatform.calls.last, 'setPlaybackSpeed');
319319
});
320320

321+
test('play before initialized does not call platform', () async {
322+
final VideoPlayerController controller = VideoPlayerController.network(
323+
'https://127.0.0.1',
324+
);
325+
expect(controller.value.isInitialized, isFalse);
326+
327+
await controller.play();
328+
329+
expect(fakeVideoPlayerPlatform.calls, isEmpty);
330+
});
331+
321332
test('play restarts from beginning if video is at end', () async {
322333
final VideoPlayerController controller = VideoPlayerController.network(
323334
'https://127.0.0.1',
@@ -373,6 +384,17 @@ void main() {
373384
expect(await controller.position, const Duration(milliseconds: 500));
374385
});
375386

387+
test('before initialized does not call platform', () async {
388+
final VideoPlayerController controller = VideoPlayerController.network(
389+
'https://127.0.0.1',
390+
);
391+
expect(controller.value.isInitialized, isFalse);
392+
393+
await controller.seekTo(const Duration(milliseconds: 500));
394+
395+
expect(fakeVideoPlayerPlatform.calls, isEmpty);
396+
});
397+
376398
test('clamps values that are too high or low', () async {
377399
final VideoPlayerController controller = VideoPlayerController.network(
378400
'https://127.0.0.1',

0 commit comments

Comments
 (0)