Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[video_player_videohole] Add 'isCompleted' event to 'VideoPlayerEvent' #766

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/video_player_videohole/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.3

* Add 'isCompleted' event to 'VideoPlayerEvent'.

## 0.5.2

* Fix new lint warnings.
Expand Down
2 changes: 1 addition & 1 deletion packages/video_player_videohole/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 28 additions & 1 deletion packages/video_player_videohole/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
JSUYA marked this conversation as resolved.
Show resolved Hide resolved

/// The [size] of the currently loaded video.
final Size size;

Expand Down Expand Up @@ -161,6 +168,7 @@ class VideoPlayerValue {
double? volume,
double? playbackSpeed,
String? errorDescription = _defaultErrorDescription,
bool? isCompleted,
}) {
return VideoPlayerValue(
duration: duration ?? this.duration,
Expand All @@ -179,6 +187,7 @@ class VideoPlayerValue {
errorDescription: errorDescription != _defaultErrorDescription
? errorDescription
: this.errorDescription,
isCompleted: isCompleted ?? this.isCompleted,
);
}

Expand All @@ -198,7 +207,8 @@ class VideoPlayerValue {
'isBuffering: $isBuffering, '
'volume: $volume, '
'playbackSpeed: $playbackSpeed, '
'errorDescription: $errorDescription)';
'errorDescription: $errorDescription, '
'isCompleted: $isCompleted),';
}
}

Expand Down Expand Up @@ -411,7 +421,19 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
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();
Expand All @@ -424,6 +446,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
// 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);
Expand Down Expand Up @@ -465,6 +488,9 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
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) {
Expand Down Expand Up @@ -780,6 +806,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
value = value.copyWith(
position: position,
caption: _getCaptionAt(position),
isCompleted: position == value.duration.end,
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/video_player_videohole/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading