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

Commit fe6d94e

Browse files
authored
[video_player] Fix persisting of errorDescription even after successful reinitialize (#4644)
This PR fixes bug which persist errorDescription even after successful initialize Fixes flutter/flutter#82772
1 parent 688f052 commit fe6d94e

File tree

4 files changed

+53
-7
lines changed

4 files changed

+53
-7
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+
## 2.2.13
2+
3+
* Fixes persisting of hasError even after successful initialize.
4+
15
## 2.2.12
26

37
* iOS: Validate size only when assets contain video tracks.

packages/video_player/video_player/lib/video_player.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ VideoPlayerPlatform get _videoPlayerPlatform {
3232
/// The duration, current position, buffering state, error state and settings
3333
/// of a [VideoPlayerController].
3434
class VideoPlayerValue {
35+
/// This constant is just to indicate that parameter is not passed to [copyWith]
36+
/// workaround for this issue https://github.com/dart-lang/language/issues/2009
37+
static const _defaultErrorDescription = 'defaultErrorDescription';
38+
3539
/// Constructs a video with the given values. Only [duration] is required. The
3640
/// rest will initialize with default values when unset.
3741
VideoPlayerValue({
@@ -138,7 +142,7 @@ class VideoPlayerValue {
138142
bool? isBuffering,
139143
double? volume,
140144
double? playbackSpeed,
141-
String? errorDescription,
145+
String? errorDescription = _defaultErrorDescription,
142146
}) {
143147
return VideoPlayerValue(
144148
duration: duration ?? this.duration,
@@ -152,7 +156,9 @@ class VideoPlayerValue {
152156
isBuffering: isBuffering ?? this.isBuffering,
153157
volume: volume ?? this.volume,
154158
playbackSpeed: playbackSpeed ?? this.playbackSpeed,
155-
errorDescription: errorDescription ?? this.errorDescription,
159+
errorDescription: errorDescription != _defaultErrorDescription
160+
? errorDescription
161+
: this.errorDescription,
156162
);
157163
}
158164

@@ -349,6 +355,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
349355
duration: event.duration,
350356
size: event.size,
351357
isInitialized: event.duration != null,
358+
errorDescription: null,
352359
);
353360
initializingCompleter.complete(null);
354361
_applyLooping();

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.2.12
6+
version: 2.2.13
77

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

packages/video_player/video_player/test/video_player_test.dart

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,19 @@ void main() {
280280

281281
expect(fakeVideoPlayerPlatform.dataSources[0].uri, 'file://a.avi');
282282
});
283+
284+
test('successful initialize on controller with error clears error',
285+
() async {
286+
final VideoPlayerController controller = VideoPlayerController.network(
287+
'https://127.0.0.1',
288+
);
289+
fakeVideoPlayerPlatform.forceInitError = true;
290+
await controller.initialize().catchError((dynamic e) {});
291+
expect(controller.value.hasError, equals(true));
292+
fakeVideoPlayerPlatform.forceInitError = false;
293+
await controller.initialize();
294+
expect(controller.value.hasError, equals(false));
295+
});
283296
});
284297

285298
test('contentUri', () async {
@@ -721,11 +734,33 @@ void main() {
721734
'errorDescription: null)');
722735
});
723736

724-
test('copyWith()', () {
725-
final VideoPlayerValue original = VideoPlayerValue.uninitialized();
726-
final VideoPlayerValue exactCopy = original.copyWith();
737+
group('copyWith()', () {
738+
test('exact copy', () {
739+
final VideoPlayerValue original = VideoPlayerValue.uninitialized();
740+
final VideoPlayerValue exactCopy = original.copyWith();
727741

728-
expect(exactCopy.toString(), original.toString());
742+
expect(exactCopy.toString(), original.toString());
743+
});
744+
test('errorDescription is not persisted when copy with null', () {
745+
final VideoPlayerValue original = VideoPlayerValue.erroneous('error');
746+
final VideoPlayerValue copy = original.copyWith(errorDescription: null);
747+
748+
expect(copy.errorDescription, null);
749+
});
750+
test('errorDescription is changed when copy with another error', () {
751+
final VideoPlayerValue original = VideoPlayerValue.erroneous('error');
752+
final VideoPlayerValue copy =
753+
original.copyWith(errorDescription: 'new error');
754+
755+
expect(copy.errorDescription, 'new error');
756+
});
757+
test('errorDescription is changed when copy with error', () {
758+
final VideoPlayerValue original = VideoPlayerValue.uninitialized();
759+
final VideoPlayerValue copy =
760+
original.copyWith(errorDescription: 'new error');
761+
762+
expect(copy.errorDescription, 'new error');
763+
});
729764
});
730765

731766
group('aspectRatio', () {

0 commit comments

Comments
 (0)