Implement CaptionListExtension for `getByTime` method function
This commit is contained in:
parent
b06e24c8db
commit
df639beecf
|
@ -84,3 +84,19 @@ extension CaptionExtension on YoutubeExplode {
|
|||
return ClosedCaptionTrack(info, captions);
|
||||
}
|
||||
}
|
||||
|
||||
/// Extension for List of [ClosedCaptions]
|
||||
extension CaptionListExtension on List<ClosedCaption> {
|
||||
/// Get the [ClosedCaption] displayed at [time].
|
||||
/// [time] can be an [int] (time in seconds) or a [Duration].
|
||||
ClosedCaption getByTime(dynamic time) {
|
||||
Duration duration;
|
||||
if (time is int) {
|
||||
duration = Duration(seconds: time);
|
||||
} else {
|
||||
duration = time;
|
||||
}
|
||||
|
||||
return firstWhere((e) => e.start <= duration && duration <= e.end);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue