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

Commit c7aa994

Browse files
[video_player] Fix disposed VideoPlayerController throwing an error when calling dispose() again (#5952)
1 parent a78274f commit c7aa994

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

packages/video_player/video_player/CHANGELOG.md

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

33
* Ignores unnecessary import warnings in preparation for [upcoming Flutter changes](https://github.com/flutter/flutter/pull/104231).
4+
* Fixes an exception when a disposed VideoPlayerController is disposed again.
45

56
## 2.4.4
67

packages/video_player/video_player/lib/video_player.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
426426

427427
@override
428428
Future<void> dispose() async {
429+
if (_isDisposed) {
430+
return;
431+
}
432+
429433
if (_creatingCompleter != null) {
430434
await _creatingCompleter!.future;
431435
if (!_isDisposed) {

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/main/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.4.4
6+
version: 2.4.5
77

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

packages/video_player/video_player/test/video_player_test.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,17 @@ void main() {
373373
expect(await controller.position, isNull);
374374
});
375375

376+
test('calling dispose() on disposed controller does not throw', () async {
377+
final VideoPlayerController controller = VideoPlayerController.network(
378+
'https://127.0.0.1',
379+
);
380+
381+
await controller.initialize();
382+
await controller.dispose();
383+
384+
expect(() async => await controller.dispose(), returnsNormally);
385+
});
386+
376387
test('play', () async {
377388
final VideoPlayerController controller = VideoPlayerController.network(
378389
'https://127.0.0.1',

0 commit comments

Comments
 (0)