import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; import 'closed_caption.dart'; part 'closed_caption_track.g.dart'; /// Track that contains closed captions in a specific language. @JsonSerializable() class ClosedCaptionTrack { /// Closed captions. final UnmodifiableListView captions; /// Initializes an instance of [ClosedCaptionTrack]. ClosedCaptionTrack(Iterable captions) : captions = UnmodifiableListView(captions); /// Gets the caption displayed at the specified point in time. /// Returns null if not found. ClosedCaption getByTime(Duration time) => captions .firstWhere((e) => time >= e.offset && time <= e.end, orElse: () => null); /// factory ClosedCaptionTrack.fromJson(Map json) => _$ClosedCaptionTrackFromJson(json); /// Map toJson() => _$ClosedCaptionTrackToJson(this); }