Skip to content

Commit e434686

Browse files
committed
extract a new class for subtitle info
1 parent 63423ec commit e434686

File tree

4 files changed

+54
-40
lines changed

4 files changed

+54
-40
lines changed

packages/video_player_avplay/lib/src/closed_caption_file.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -658,31 +658,31 @@ class SubtitleAttribute {
658658

659659
/// Parses a subtitle from a [VideoEvent] into a [PictureCaption] or a list of [TextCaption]s.
660660
(PictureCaption?, List<TextCaption>?) parseSubtitle(
661-
Duration position, VideoEvent event) {
662-
final Duration textDuration = event.textDuration == 0
661+
Duration position, SubtitlesInfo subtitlesInfo) {
662+
final Duration textDuration = subtitlesInfo.textDuration == 0
663663
? Duration.zero
664-
: Duration(milliseconds: event.textDuration!);
665-
if (event.pictureInfo?.isNotEmpty ?? false) {
664+
: Duration(milliseconds: subtitlesInfo.textDuration!);
665+
if (subtitlesInfo.pictureInfo?.isNotEmpty ?? false) {
666666
final PictureCaption pictureCaption = PictureCaption(
667667
number: 0,
668668
start: position,
669669
end: position + textDuration,
670-
picture: event.pictureInfo!['picture'] as Uint8List?,
671-
pictureWidth: event.pictureInfo!['pictureWidth'] as double?,
672-
pictureHeight: event.pictureInfo!['pictureHeight'] as double?,
670+
picture: subtitlesInfo.pictureInfo!['picture'] as Uint8List?,
671+
pictureWidth: subtitlesInfo.pictureInfo!['pictureWidth'] as double?,
672+
pictureHeight: subtitlesInfo.pictureInfo!['pictureHeight'] as double?,
673673
);
674674
return (pictureCaption, null);
675675
} else {
676676
final int textLines =
677-
(event.textsInfo == null || event.textsInfo![0] == null)
677+
(subtitlesInfo.textsInfo == null || subtitlesInfo.textsInfo![0] == null)
678678
? 0
679-
: event.textsInfo!.length;
679+
: subtitlesInfo.textsInfo!.length;
680680

681681
if (textLines > 0) {
682682
final List<TextCaption> textCaptions = <TextCaption>[];
683683
for (int i = 0; i < textLines; i++) {
684684
final Map<Object?, Object?> textInfo =
685-
event.textsInfo![i] as Map<Object?, Object?>;
685+
subtitlesInfo.textsInfo![i] as Map<Object?, Object?>;
686686
final String? text = textInfo['text'] as String?;
687687
final List<dynamic>? subtitleAttrList =
688688
textInfo['attributes'] as List<dynamic>?;

packages/video_player_avplay/lib/src/video_player_tizen.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,10 @@ class VideoPlayerTizen extends VideoPlayerPlatform {
436436
case 'subtitleUpdate':
437437
return VideoEvent(
438438
eventType: VideoEventType.subtitleUpdate,
439-
textsInfo: map['textsInfo'] as List<dynamic>?,
440-
textDuration: map['duration'] as int?,
441-
pictureInfo: map['pictureInfo'] as Map<Object?, Object?>?,
439+
subtitlesInfo: SubtitlesInfo(
440+
map['duration'] as int?,
441+
map['textsInfo'] as List<dynamic>?,
442+
map['pictureInfo'] as Map<Object?, Object?>?),
442443
);
443444
case 'isPlayingStateUpdate':
444445
return VideoEvent(

packages/video_player_avplay/lib/video_player.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
654654
value = value.copyWith(isBuffering: false);
655655
case VideoEventType.subtitleUpdate:
656656
final (PictureCaption?, List<TextCaption>?) subtitles =
657-
parseSubtitle(value.position, event);
657+
parseSubtitle(value.position, event.subtitlesInfo!);
658658
value = value.copyWith(
659659
pictureCaption: subtitles.$1, textCaptions: subtitles.$2);
660660
case VideoEventType.isPlayingStateUpdate:

packages/video_player_avplay/lib/video_player_platform_interface.dart

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,10 @@ class VideoEvent {
528528
this.duration,
529529
this.size,
530530
this.buffered,
531-
this.textsInfo,
532-
this.textDuration,
533531
this.isPlaying,
534532
this.adInfo,
535-
this.pictureInfo,
536533
this.manifestInfo,
534+
this.subtitlesInfo,
537535
});
538536

539537
/// The type of the event.
@@ -554,16 +552,6 @@ class VideoEvent {
554552
/// Only used if [eventType] is [VideoEventType.bufferingUpdate].
555553
final int? buffered;
556554

557-
/// Text and attributes of the video subtitle.
558-
///
559-
/// Only used if [eventType] is [VideoEventType.subtitleUpdate].
560-
final List<dynamic>? textsInfo;
561-
562-
/// The duration of text
563-
///
564-
/// Only used if [eventType] is [VideoEventType.subtitleUpdate].
565-
final int? textDuration;
566-
567555
/// Whether the video is currently playing.
568556
///
569557
/// Only used if [eventType] is [VideoEventType.isPlayingStateUpdate].
@@ -574,16 +562,16 @@ class VideoEvent {
574562
/// Only used if [eventType] is [VideoEventType.adFromDash].
575563
final Map<Object?, Object?>? adInfo;
576564

577-
/// Subtitle picture info of the video. Includes the picture and its width and height.
578-
///
579-
/// Only used if [eventType] is [VideoEventType.subtitleUpdate].
580-
final Map<Object?, Object?>? pictureInfo;
581-
582565
/// The manifest information in dash.
583566
///
584567
/// Only used if [eventType] is [VideoEventType.manifestInfoUpdated].
585568
final String? manifestInfo;
586569

570+
/// The subtitle information of the video.
571+
///
572+
/// Only used if [eventType] is [VideoEventType.subtitleUpdate].
573+
final SubtitlesInfo? subtitlesInfo;
574+
587575
@override
588576
bool operator ==(Object other) {
589577
return identical(this, other) ||
@@ -593,12 +581,10 @@ class VideoEvent {
593581
duration == other.duration &&
594582
size == other.size &&
595583
buffered == other.buffered &&
596-
listEquals(textsInfo, other.textsInfo) &&
597-
textDuration == other.textDuration &&
598584
isPlaying == other.isPlaying &&
599585
mapEquals(adInfo, other.adInfo) &&
600-
mapEquals(pictureInfo, other.pictureInfo) &&
601-
manifestInfo == other.manifestInfo;
586+
manifestInfo == other.manifestInfo &&
587+
subtitlesInfo == other.subtitlesInfo;
602588
}
603589

604590
@override
@@ -607,12 +593,10 @@ class VideoEvent {
607593
duration.hashCode ^
608594
size.hashCode ^
609595
buffered.hashCode ^
610-
textsInfo.hashCode ^
611-
textDuration.hashCode ^
612596
isPlaying.hashCode ^
613597
adInfo.hashCode ^
614-
pictureInfo.hashCode ^
615-
manifestInfo.hashCode;
598+
manifestInfo.hashCode ^
599+
subtitlesInfo.hashCode;
616600
}
617601

618602
/// Type of the event.
@@ -722,6 +706,35 @@ class DurationRange {
722706
int get hashCode => start.hashCode ^ end.hashCode;
723707
}
724708

709+
/// The subtitle information of the video. Contains the text duration, text and attributes, and picture info.
710+
@immutable
711+
class SubtitlesInfo {
712+
/// Creates an instance of [SubtitlesInfo].
713+
const SubtitlesInfo(this.textDuration, this.textsInfo, this.pictureInfo);
714+
715+
/// The duration of text.
716+
final int? textDuration;
717+
718+
/// Text and attributes of the video subtitle.
719+
final List<dynamic>? textsInfo;
720+
721+
/// Subtitle picture info of the video. Includes the picture and its width and height.
722+
final Map<Object?, Object?>? pictureInfo;
723+
724+
@override
725+
bool operator ==(Object other) {
726+
return identical(this, other) ||
727+
other is SubtitlesInfo &&
728+
listEquals(textsInfo, other.textsInfo) &&
729+
textDuration == other.textDuration &&
730+
mapEquals(pictureInfo, other.pictureInfo);
731+
}
732+
733+
@override
734+
int get hashCode =>
735+
textDuration.hashCode ^ textsInfo.hashCode ^ pictureInfo.hashCode;
736+
}
737+
725738
/// [VideoPlayerOptions] can be optionally used to set additional player settings
726739
@immutable
727740
class VideoPlayerOptions {

0 commit comments

Comments
 (0)