Skip to content

Commit

Permalink
[video_player] Fix disposed VideoPlayerController throwing an error w…
Browse files Browse the repository at this point in the history
…hen calling dispose() again (#5952)
  • Loading branch information
navaronbracke authored Jun 16, 2022
1 parent a78274f commit c7aa994
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/video_player/video_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT
## 2.4.5

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

## 2.4.4

Expand Down
4 changes: 4 additions & 0 deletions packages/video_player/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {

@override
Future<void> dispose() async {
if (_isDisposed) {
return;
}

if (_creatingCompleter != null) {
await _creatingCompleter!.future;
if (!_isDisposed) {
Expand Down
2 changes: 1 addition & 1 deletion packages/video_player/video_player/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for displaying inline video with other Flutter
widgets on Android, iOS, and web.
repository: https://github.com/flutter/plugins/tree/main/packages/video_player/video_player
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
version: 2.4.4
version: 2.4.5

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down
11 changes: 11 additions & 0 deletions packages/video_player/video_player/test/video_player_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,17 @@ void main() {
expect(await controller.position, isNull);
});

test('calling dispose() on disposed controller does not throw', () async {
final VideoPlayerController controller = VideoPlayerController.network(
'https://127.0.0.1',
);

await controller.initialize();
await controller.dispose();

expect(() async => await controller.dispose(), returnsNormally);
});

test('play', () async {
final VideoPlayerController controller = VideoPlayerController.network(
'https://127.0.0.1',
Expand Down

0 comments on commit c7aa994

Please sign in to comment.