Skip to content

Commit 6a7709a

Browse files
authored
[video_player_avplay] Fix subtitle rendering issue (#935)
1 parent 41cf036 commit 6a7709a

File tree

6 files changed

+28
-6
lines changed

6 files changed

+28
-6
lines changed

packages/video_player_avplay/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.7.5
2+
* Fix the issue of subtitles remaining longer than their end time.
3+
14
## 0.7.4
25
* Update plusplayer
36
1. [DASH] Fix this issue of audio switching not working in the dash video stream.

packages/video_player_avplay/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ To use this package, add `video_player_avplay` as a dependency in your `pubspec.
1212

1313
```yaml
1414
dependencies:
15-
video_player_avplay: ^0.7.4
15+
video_player_avplay: ^0.7.5
1616
```
1717
1818
Then you can import `video_player_avplay` in your Dart code:

packages/video_player_avplay/lib/src/video_player_tizen.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ class VideoPlayerTizen extends VideoPlayerPlatform {
437437
return VideoEvent(
438438
eventType: VideoEventType.subtitleUpdate,
439439
text: map['text']! as String,
440+
textDuration: map['duration'] as int?,
440441
subtitleAttributes: map['attributes']! as List<dynamic>,
441442
);
442443
case 'isPlayingStateUpdate':

packages/video_player_avplay/lib/video_player.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ class VideoPlayerValue {
182182
return aspectRatio;
183183
}
184184

185+
/// Returns the [Caption] that should be displayed based on the current [position].
186+
/// If the value of [caption.end] has greater than the current [position], this will be a [Caption.none] object.
187+
/// Only used for [copyWith].
188+
Caption get _currentCaption {
189+
return position > caption.end ? Caption.none : caption;
190+
}
191+
185192
/// Returns a new instance that has the same values as this current instance,
186193
/// except for any overrides passed in as arguments to [copyWidth].
187194
VideoPlayerValue copyWith({
@@ -206,7 +213,7 @@ class VideoPlayerValue {
206213
duration: duration ?? this.duration,
207214
size: size ?? this.size,
208215
position: position ?? this.position,
209-
caption: caption ?? this.caption,
216+
caption: caption ?? _currentCaption,
210217
captionOffset: captionOffset ?? this.captionOffset,
211218
tracks: tracks ?? this.tracks,
212219
buffered: buffered ?? this.buffered,
@@ -594,7 +601,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
594601
// we use pause() and seekTo() to ensure the platform stops playing
595602
// and seeks to the last frame of the video.
596603
pause().then((void pauseResult) => seekTo(value.duration.end));
597-
value = value.copyWith(isCompleted: true);
604+
value = value.copyWith(isCompleted: true, caption: Caption.none);
598605
_durationTimer?.cancel();
599606
case VideoEventType.bufferingUpdate:
600607
value = value.copyWith(buffered: event.buffered);
@@ -607,10 +614,13 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
607614
SubtitleAttribute.fromEventSubtitleAttrList(
608615
event.subtitleAttributes,
609616
);
617+
final Duration textDuration = event.textDuration == 0
618+
? Duration.zero
619+
: Duration(milliseconds: event.textDuration!);
610620
final Caption caption = Caption(
611621
number: 0,
612622
start: value.position,
613-
end: value.position + (event.duration?.end ?? Duration.zero),
623+
end: value.position + textDuration,
614624
text: event.text ?? '',
615625
subtitleAttributes: subtitleAttributes,
616626
);
@@ -1125,7 +1135,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
11251135
/// [Caption].
11261136
Caption _getCaptionAt(Duration position) {
11271137
if (_closedCaptionFile == null) {
1128-
return value.caption;
1138+
return position > value.caption.end ? Caption.none : value.caption;
11291139
}
11301140

11311141
final Duration delayedPosition = position + value.captionOffset;

packages/video_player_avplay/lib/video_player_platform_interface.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ class VideoEvent {
555555
this.size,
556556
this.buffered,
557557
this.text,
558+
this.textDuration,
558559
this.isPlaying,
559560
this.subtitleAttributes,
560561
this.adInfo,
@@ -583,6 +584,11 @@ class VideoEvent {
583584
/// Only used if [eventType] is [VideoEventType.subtitleUpdate].
584585
final String? text;
585586

587+
/// The duration of text
588+
///
589+
/// Only used if [eventType] is [VideoEventType.subtitleUpdate].
590+
final int? textDuration;
591+
586592
/// Whether the video is currently playing.
587593
///
588594
/// Only used if [eventType] is [VideoEventType.isPlayingStateUpdate].
@@ -606,6 +612,7 @@ class VideoEvent {
606612
size == other.size &&
607613
buffered == other.buffered &&
608614
text == other.text &&
615+
textDuration == other.textDuration &&
609616
isPlaying == other.isPlaying &&
610617
subtitleAttributes == other.subtitleAttributes &&
611618
adInfo == other.adInfo;
@@ -618,6 +625,7 @@ class VideoEvent {
618625
size.hashCode ^
619626
buffered.hashCode ^
620627
text.hashCode ^
628+
textDuration.hashCode ^
621629
isPlaying.hashCode ^
622630
subtitleAttributes.hashCode ^
623631
adInfo.hashCode;

packages/video_player_avplay/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: video_player_avplay
22
description: Flutter plugin for displaying inline video on Tizen TV devices.
33
homepage: https://github.com/flutter-tizen/plugins
44
repository: https://github.com/flutter-tizen/plugins/tree/master/packages/video_player_avplay
5-
version: 0.7.4
5+
version: 0.7.5
66

77
environment:
88
sdk: ">=3.1.0 <4.0.0"

0 commit comments

Comments
 (0)