From ee4a050ea7c26583984e82d9c0af0ea17ccf97bc Mon Sep 17 00:00:00 2001 From: Xiaowei Guan Date: Tue, 5 Nov 2024 19:09:27 +0800 Subject: [PATCH] Add isCompleted event --- packages/video_player_videohole/CHANGELOG.md | 4 +++ packages/video_player_videohole/README.md | 2 +- .../lib/video_player.dart | 29 ++++++++++++++++++- packages/video_player_videohole/pubspec.yaml | 2 +- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/packages/video_player_videohole/CHANGELOG.md b/packages/video_player_videohole/CHANGELOG.md index d71b915a7..28ac300e7 100644 --- a/packages/video_player_videohole/CHANGELOG.md +++ b/packages/video_player_videohole/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.5.3 + +* Add 'isCompleted' event to 'VideoPlayerEvent'. + ## 0.5.2 * Fix new lint warnings. diff --git a/packages/video_player_videohole/README.md b/packages/video_player_videohole/README.md index 6353d4f85..a5dd22770 100644 --- a/packages/video_player_videohole/README.md +++ b/packages/video_player_videohole/README.md @@ -12,7 +12,7 @@ To use this package, add `video_player_videohole` as a dependency in your `pubsp ```yaml dependencies: - video_player_videohole: ^0.5.2 + video_player_videohole: ^0.5.3 ``` Then you can import `video_player_videohole` in your Dart code: diff --git a/packages/video_player_videohole/lib/video_player.dart b/packages/video_player_videohole/lib/video_player.dart index 9b079312f..6f40216fa 100644 --- a/packages/video_player_videohole/lib/video_player.dart +++ b/packages/video_player_videohole/lib/video_player.dart @@ -53,6 +53,7 @@ class VideoPlayerValue { this.volume = 1.0, this.playbackSpeed = 1.0, this.errorDescription, + this.isCompleted = false, }); /// Returns an instance for a video that hasn't been loaded. @@ -117,6 +118,12 @@ class VideoPlayerValue { /// If [hasError] is false this is `null`. final String? errorDescription; + /// True if video has finished playing to end. + /// + /// Reverts to false if video position changes, or video begins playing. + /// Does not update if video is looping. + final bool isCompleted; + /// The [size] of the currently loaded video. final Size size; @@ -161,6 +168,7 @@ class VideoPlayerValue { double? volume, double? playbackSpeed, String? errorDescription = _defaultErrorDescription, + bool? isCompleted, }) { return VideoPlayerValue( duration: duration ?? this.duration, @@ -179,6 +187,7 @@ class VideoPlayerValue { errorDescription: errorDescription != _defaultErrorDescription ? errorDescription : this.errorDescription, + isCompleted: isCompleted ?? this.isCompleted, ); } @@ -198,7 +207,8 @@ class VideoPlayerValue { 'isBuffering: $isBuffering, ' 'volume: $volume, ' 'playbackSpeed: $playbackSpeed, ' - 'errorDescription: $errorDescription)'; + 'errorDescription: $errorDescription, ' + 'isCompleted: $isCompleted),'; } } @@ -411,7 +421,19 @@ class VideoPlayerController extends ValueNotifier { size: event.size, isInitialized: event.duration != null, errorDescription: null, + isCompleted: false, ); + assert( + !initializingCompleter.isCompleted, + 'VideoPlayerController already initialized. This is typically a ' + 'sign that an implementation of the VideoPlayerPlatform ' + '(${_videoPlayerPlatform.runtimeType}) has a bug and is sending ' + 'more than one initialized event per instance.', + ); + if (initializingCompleter.isCompleted) { + throw StateError('VideoPlayerController already initialized'); + } + initializingCompleter.complete(null); _applyLooping(); _applyVolume(); @@ -424,6 +446,7 @@ class VideoPlayerController extends ValueNotifier { // we use pause() and seekTo() to ensure the platform stops playing // and seeks to the last frame of the video. pause().then((void pauseResult) => seekTo(value.duration.end)); + value = value.copyWith(isCompleted: true); _durationTimer?.cancel(); case VideoEventType.bufferingUpdate: value = value.copyWith(buffered: event.buffered); @@ -465,6 +488,9 @@ class VideoPlayerController extends ValueNotifier { void errorListener(Object obj) { final PlatformException e = obj as PlatformException; value = VideoPlayerValue.erroneous(e.message!); + if (!initializingCompleter.isCompleted) { + initializingCompleter.completeError(obj); + } _timer?.cancel(); _durationTimer?.cancel(); if (!initializingCompleter.isCompleted) { @@ -780,6 +806,7 @@ class VideoPlayerController extends ValueNotifier { value = value.copyWith( position: position, caption: _getCaptionAt(position), + isCompleted: position == value.duration.end, ); } diff --git a/packages/video_player_videohole/pubspec.yaml b/packages/video_player_videohole/pubspec.yaml index ae6fd4ffd..e0920652b 100644 --- a/packages/video_player_videohole/pubspec.yaml +++ b/packages/video_player_videohole/pubspec.yaml @@ -2,7 +2,7 @@ name: video_player_videohole description: Flutter plugin for displaying inline video on Tizen TV devices. homepage: https://github.com/flutter-tizen/plugins repository: https://github.com/flutter-tizen/plugins/tree/master/packages/video_player_videohole -version: 0.5.2 +version: 0.5.3 environment: sdk: ">=3.1.0 <4.0.0"