youtube_explode/lib/src/videos/closed_captions/closed_caption_track.dart

31 lines
934 B
Dart
Raw Normal View History

2020-06-03 23:02:21 +02:00
2021-03-11 14:20:10 +01:00
import 'package:collection/collection.dart';
2020-11-13 09:21:01 +01:00
import 'package:json_annotation/json_annotation.dart';
2020-06-03 23:02:21 +02:00
import 'closed_caption.dart';
2020-11-13 09:21:01 +01:00
part 'closed_caption_track.g.dart';
2020-06-03 23:02:21 +02:00
/// Track that contains closed captions in a specific language.
2020-11-13 09:21:01 +01:00
@JsonSerializable()
2020-06-03 23:02:21 +02:00
class ClosedCaptionTrack {
/// Closed captions.
final UnmodifiableListView<ClosedCaption> captions;
/// Initializes an instance of [ClosedCaptionTrack].
ClosedCaptionTrack(Iterable<ClosedCaption> captions)
: captions = UnmodifiableListView(captions);
/// Gets the caption displayed at the specified point in time.
/// Returns null if not found.
2021-03-11 14:20:10 +01:00
ClosedCaption? getByTime(Duration time) =>
captions.firstWhereOrNull((e) => time >= e.offset && time <= e.end);
2020-11-13 09:21:01 +01:00
///
factory ClosedCaptionTrack.fromJson(Map<String, dynamic> json) =>
_$ClosedCaptionTrackFromJson(json);
///
Map<String, dynamic> toJson() => _$ClosedCaptionTrackToJson(this);
2020-06-03 23:02:21 +02:00
}