diff --git a/packages/video_player_avplay/CHANGELOG.md b/packages/video_player_avplay/CHANGELOG.md index 416a2bd59..aefb02899 100644 --- a/packages/video_player_avplay/CHANGELOG.md +++ b/packages/video_player_avplay/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.7.5 +* Fix the issue of subtitles remaining longer than their end time. + ## 0.7.4 * Update plusplayer 1. [DASH] Fix this issue of audio switching not working in the dash video stream. diff --git a/packages/video_player_avplay/README.md b/packages/video_player_avplay/README.md index 97293ce3c..c80faba91 100644 --- a/packages/video_player_avplay/README.md +++ b/packages/video_player_avplay/README.md @@ -12,7 +12,7 @@ To use this package, add `video_player_avplay` as a dependency in your `pubspec. ```yaml dependencies: - video_player_avplay: ^0.7.4 + video_player_avplay: ^0.7.5 ``` Then you can import `video_player_avplay` in your Dart code: diff --git a/packages/video_player_avplay/lib/src/video_player_tizen.dart b/packages/video_player_avplay/lib/src/video_player_tizen.dart index ec133cdef..03d4af72d 100644 --- a/packages/video_player_avplay/lib/src/video_player_tizen.dart +++ b/packages/video_player_avplay/lib/src/video_player_tizen.dart @@ -437,6 +437,7 @@ class VideoPlayerTizen extends VideoPlayerPlatform { return VideoEvent( eventType: VideoEventType.subtitleUpdate, text: map['text']! as String, + textDuration: map['duration'] as int?, subtitleAttributes: map['attributes']! as List, ); case 'isPlayingStateUpdate': diff --git a/packages/video_player_avplay/lib/video_player.dart b/packages/video_player_avplay/lib/video_player.dart index 9aa15ef99..674e9cedd 100644 --- a/packages/video_player_avplay/lib/video_player.dart +++ b/packages/video_player_avplay/lib/video_player.dart @@ -182,6 +182,13 @@ class VideoPlayerValue { return aspectRatio; } + /// Returns the [Caption] that should be displayed based on the current [position]. + /// If the value of [caption.end] has greater than the current [position], this will be a [Caption.none] object. + /// Only used for [copyWith]. + Caption get _currentCaption { + return position > caption.end ? Caption.none : caption; + } + /// Returns a new instance that has the same values as this current instance, /// except for any overrides passed in as arguments to [copyWidth]. VideoPlayerValue copyWith({ @@ -206,7 +213,7 @@ class VideoPlayerValue { duration: duration ?? this.duration, size: size ?? this.size, position: position ?? this.position, - caption: caption ?? this.caption, + caption: caption ?? _currentCaption, captionOffset: captionOffset ?? this.captionOffset, tracks: tracks ?? this.tracks, buffered: buffered ?? this.buffered, @@ -594,7 +601,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); + value = value.copyWith(isCompleted: true, caption: Caption.none); _durationTimer?.cancel(); case VideoEventType.bufferingUpdate: value = value.copyWith(buffered: event.buffered); @@ -607,10 +614,13 @@ class VideoPlayerController extends ValueNotifier { SubtitleAttribute.fromEventSubtitleAttrList( event.subtitleAttributes, ); + final Duration textDuration = event.textDuration == 0 + ? Duration.zero + : Duration(milliseconds: event.textDuration!); final Caption caption = Caption( number: 0, start: value.position, - end: value.position + (event.duration?.end ?? Duration.zero), + end: value.position + textDuration, text: event.text ?? '', subtitleAttributes: subtitleAttributes, ); @@ -1125,7 +1135,7 @@ class VideoPlayerController extends ValueNotifier { /// [Caption]. Caption _getCaptionAt(Duration position) { if (_closedCaptionFile == null) { - return value.caption; + return position > value.caption.end ? Caption.none : value.caption; } final Duration delayedPosition = position + value.captionOffset; diff --git a/packages/video_player_avplay/lib/video_player_platform_interface.dart b/packages/video_player_avplay/lib/video_player_platform_interface.dart index c55a51e17..cbc21b86e 100644 --- a/packages/video_player_avplay/lib/video_player_platform_interface.dart +++ b/packages/video_player_avplay/lib/video_player_platform_interface.dart @@ -555,6 +555,7 @@ class VideoEvent { this.size, this.buffered, this.text, + this.textDuration, this.isPlaying, this.subtitleAttributes, this.adInfo, @@ -583,6 +584,11 @@ class VideoEvent { /// Only used if [eventType] is [VideoEventType.subtitleUpdate]. final String? text; + /// The duration of text + /// + /// Only used if [eventType] is [VideoEventType.subtitleUpdate]. + final int? textDuration; + /// Whether the video is currently playing. /// /// Only used if [eventType] is [VideoEventType.isPlayingStateUpdate]. @@ -606,6 +612,7 @@ class VideoEvent { size == other.size && buffered == other.buffered && text == other.text && + textDuration == other.textDuration && isPlaying == other.isPlaying && subtitleAttributes == other.subtitleAttributes && adInfo == other.adInfo; @@ -618,6 +625,7 @@ class VideoEvent { size.hashCode ^ buffered.hashCode ^ text.hashCode ^ + textDuration.hashCode ^ isPlaying.hashCode ^ subtitleAttributes.hashCode ^ adInfo.hashCode; diff --git a/packages/video_player_avplay/pubspec.yaml b/packages/video_player_avplay/pubspec.yaml index c517b6013..8c5590e87 100644 --- a/packages/video_player_avplay/pubspec.yaml +++ b/packages/video_player_avplay/pubspec.yaml @@ -2,7 +2,7 @@ name: video_player_avplay 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_avplay -version: 0.7.4 +version: 0.7.5 environment: sdk: ">=3.1.0 <4.0.0"