pub struct CaptionTrack {
pub cues: Vec<Cue>,
pub language: String,
pub label: String,
}Expand description
An ordered list of Cues plus the metadata a subtitle track carries.
use threers_captions::CaptionTrack;
let track = CaptionTrack::new()
.language("en")
.label("English")
.cue(0.0, 2.0, "First line")
.cue(2.0, 4.0, "Second line");
assert_eq!(track.duration(), 4.0);
assert!(track.to_vtt().starts_with("WEBVTT"));Fields§
§cues: Vec<Cue>§language: StringBCP-47 language tag ("en", "pt-BR", …). Empty means undetermined.
label: StringHuman-readable track name shown in player menus.
Implementations§
Source§impl CaptionTrack
impl CaptionTrack
Sourcepub fn new() -> CaptionTrack
pub fn new() -> CaptionTrack
An empty track.
Sourcepub fn language(self, language: impl Into<String>) -> CaptionTrack
pub fn language(self, language: impl Into<String>) -> CaptionTrack
Set the BCP-47 language tag.
Sourcepub fn label(self, label: impl Into<String>) -> CaptionTrack
pub fn label(self, label: impl Into<String>) -> CaptionTrack
Set the human-readable track label.
Sourcepub fn cue(self, start: f64, end: f64, text: impl Into<String>) -> CaptionTrack
pub fn cue(self, start: f64, end: f64, text: impl Into<String>) -> CaptionTrack
Append a cue (builder form). Keeps cues sorted by start time.
Sourcepub fn sort(&mut self)
pub fn sort(&mut self)
Re-sort cues by start time (then end time). Only needed if cues was
mutated directly.
Sourcepub fn active_at(&self, time: f64) -> Vec<&Cue>
pub fn active_at(&self, time: f64) -> Vec<&Cue>
Every cue showing at time seconds, in track order.
Sourcepub fn cue_at(&self, time: f64) -> Option<&Cue>
pub fn cue_at(&self, time: f64) -> Option<&Cue>
The first cue showing at time seconds — the common case, since most
tracks show one cue at a time.
Sourcepub fn text_at(&self, time: f64) -> String
pub fn text_at(&self, time: f64) -> String
Concatenated plain_text of every cue active at
time, joined with newlines. Empty when nothing is showing.
Sourcepub fn shift(&mut self, seconds: f64)
pub fn shift(&mut self, seconds: f64)
Shift every cue by seconds (negative moves earlier). Cues never move
before zero.
Sourcepub fn scale(&mut self, factor: f64)
pub fn scale(&mut self, factor: f64)
Scale every cue time by factor — e.g. 24.0 / 25.0 to retime a 25 fps
track for 24 fps playback.
Sourcepub fn parse_srt(text: &str) -> Result<CaptionTrack, CaptionError>
pub fn parse_srt(text: &str) -> Result<CaptionTrack, CaptionError>
Parse SubRip (.srt).
Sourcepub fn parse_vtt(text: &str) -> Result<CaptionTrack, CaptionError>
pub fn parse_vtt(text: &str) -> Result<CaptionTrack, CaptionError>
Parse WebVTT (.vtt).
Sourcepub fn parse(text: &str) -> Result<CaptionTrack, CaptionError>
pub fn parse(text: &str) -> Result<CaptionTrack, CaptionError>
Parse either format, sniffing the WEBVTT magic.
Sourcepub fn to_format(&self, format: CaptionFormat) -> String
pub fn to_format(&self, format: CaptionFormat) -> String
Serialize to format.
Trait Implementations§
Source§impl Clone for CaptionTrack
impl Clone for CaptionTrack
Source§fn clone(&self) -> CaptionTrack
fn clone(&self) -> CaptionTrack
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CaptionTrack
impl Debug for CaptionTrack
Source§impl Default for CaptionTrack
impl Default for CaptionTrack
Source§fn default() -> CaptionTrack
fn default() -> CaptionTrack
Source§impl PartialEq for CaptionTrack
impl PartialEq for CaptionTrack
impl StructuralPartialEq for CaptionTrack
Auto Trait Implementations§
impl Forget for CaptionTrack
impl Freeze for CaptionTrack
impl Move for CaptionTrack
impl RefUnwindSafe for CaptionTrack
impl Send for CaptionTrack
impl Sync for CaptionTrack
impl Unpin for CaptionTrack
impl UnsafeUnpin for CaptionTrack
impl UnwindSafe for CaptionTrack
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more