Skip to main content

MediaPlayer

Trait MediaPlayer 

Source
pub trait MediaPlayer: Send {
Show 14 methods // Required methods fn open(&mut self, req: OpenRequest) -> Result<(), PlayerError>; fn play(&mut self) -> Result<(), PlayerError>; fn pause(&mut self) -> Result<(), PlayerError>; fn close(&mut self) -> Result<(), PlayerError>; fn seek(&mut self, to: Duration) -> Result<(), PlayerError>; fn set_volume(&mut self, volume: f32) -> Result<(), PlayerError>; fn set_muted(&mut self, muted: bool) -> Result<(), PlayerError>; fn set_rate(&mut self, rate: f64) -> Result<(), PlayerError>; fn select_audio_track( &mut self, index: Option<i32>, ) -> Result<(), PlayerError>; fn select_subtitle_track( &mut self, index: Option<i32>, ) -> Result<(), PlayerError>; fn snapshot(&self) -> PlaybackSnapshot; fn capabilities(&self) -> Capabilities; // Provided methods fn set_audio_settings( &mut self, _settings: &AudioSettings, ) -> Result<(), PlayerError> { ... } fn audio_settings(&self) -> AudioSettings { ... }
}
Expand description

Anything that can present media.

Implementations: MpvPlayer (Linux/Windows), ExoPlayerPlayer (Android), WebviewPlayer (HTML5 element), and FakePlayer for tests. Every one of them must pass [super::conformance].

Required Methods§

Source

fn open(&mut self, req: OpenRequest) -> Result<(), PlayerError>

Present req.selection, beginning at req.start.

One operation, deliberately. An engine that cannot start at an offset natively absorbs that internally — by deferring until loaded, or by re-opening — because it is the only layer that knows when it can. Callers must never follow open with a seek to achieve a start position; that is the bug this signature exists to prevent.

Source

fn play(&mut self) -> Result<(), PlayerError>

Source

fn pause(&mut self) -> Result<(), PlayerError>

Source

fn close(&mut self) -> Result<(), PlayerError>

Stop and release the current item.

Must be idempotent and must leave the engine silent. “Stopped” and “producing no audio” were not the same thing in the previous design, and the gap between them is audible.

Source

fn seek(&mut self, to: Duration) -> Result<(), PlayerError>

Seek to an absolute position on the item’s own timeline.

Whether that is an in-place seek or a re-open of the stream is the engine’s business: hls.js seeks within a VOD playlist, mpv’s HLS demuxer cannot make a server transcode from a new offset. Callers state the destination and nothing else.

Source

fn set_volume(&mut self, volume: f32) -> Result<(), PlayerError>

Source

fn set_muted(&mut self, muted: bool) -> Result<(), PlayerError>

Source

fn set_rate(&mut self, rate: f64) -> Result<(), PlayerError>

Source

fn select_audio_track(&mut self, index: Option<i32>) -> Result<(), PlayerError>

Source

fn select_subtitle_track( &mut self, index: Option<i32>, ) -> Result<(), PlayerError>

Source

fn snapshot(&self) -> PlaybackSnapshot

One coherent read of the engine’s state.

Source

fn capabilities(&self) -> Capabilities

Provided Methods§

Source

fn set_audio_settings( &mut self, _settings: &AudioSettings, ) -> Result<(), PlayerError>

Apply EQ, normalisation and gapless settings.

Provided rather than required: engines that cannot honour them say so through Capabilities::audio_settings and inherit this no-op, instead of every implementation carrying an Ok(()) it does not mean.

Source

fn audio_settings(&self) -> AudioSettings

Implementors§