Skip to main content

MediaPlayer

Trait MediaPlayer 

Source
pub trait MediaPlayer: Send + Sync {
Show 15 methods // Required methods fn capabilities(&self) -> MediaCapabilities; fn prepare(&self, item: &MediaItem) -> Result<(), MediaError>; fn play(&self) -> Result<(), MediaError>; fn pause(&self); fn stop(&self); fn set_volume(&self, volume: f32); // Provided methods fn seek_to(&self, _position: Duration) -> Result<(), MediaError> { ... } fn set_speed(&self, _speed: f32) -> bool { ... } fn set_looping(&self, _looping: bool) { ... } fn set_analysis_enabled(&self, _enabled: bool) -> bool { ... } fn set_session_metadata(&self, _metadata: &MediaMetadata) { ... } fn equalizer_bands(&self) -> Vec<EqualizerBand> { ... } fn set_equalizer(&self, _settings: &EqualizerSettings) { ... } fn audio_extensions(&self) -> Vec<&'static str> { ... } fn probe_duration(&self, _item: &MediaItem) -> Option<Duration> { ... }
}
Expand description

Re-export framework services (HTTP, URI, etc.) from the dedicated services crate. A platform media stack.

A backend opens items, drives the transport, and publishes what happens through publish_playback_state, publish_playback_progress, publish_audio_focus, publish_media_command and publish_media_samples. Nothing here is polled, and no method blocks for the length of an item.

Applications call the free functions — open_media, play_media, seek_media — rather than this trait: the free functions are where volume is combined with the focus gain, where the background-work lease is held, and where a seek is clamped to the item.

Required Methods§

Source

fn capabilities(&self) -> MediaCapabilities

What this backend can do. Read by screens to decide which controls exist at all.

Source

fn prepare(&self, item: &MediaItem) -> Result<(), MediaError>

Opens item and gets it ready to play, without playing it.

Returns as soon as the request is accepted; the item’s progress arrives as PlaybackState, because opening a network item takes as long as the network does.

Source

fn play(&self) -> Result<(), MediaError>

Starts, or resumes, the open item.

Source

fn pause(&self)

Stops without giving up the position.

Source

fn stop(&self)

Stops, closes the item and releases the output device.

Source

fn set_volume(&self, volume: f32)

Sets the output gain, already combined with the audio-focus gain by set_media_volume. 0.0 is silent, 1.0 is the item as recorded.

Provided Methods§

Source

fn seek_to(&self, _position: Duration) -> Result<(), MediaError>

Moves the position within the open item.

Source

fn set_speed(&self, _speed: f32) -> bool

Sets the playback rate, 1.0 being as recorded. Returns false where the backend does not have one.

Source

fn set_looping(&self, _looping: bool)

Repeats the open item when it reaches its end.

Source

fn set_analysis_enabled(&self, _enabled: bool) -> bool

Starts or stops publishing MediaSamples. Returns false where the backend cannot produce them, which is also what MediaCapabilities::analysis reports.

Source

fn set_session_metadata(&self, _metadata: &MediaMetadata)

Hands metadata to the platform media session. Called again whenever the application learns more about the open item, because tags are often parsed after playback has already started.

Source

fn equalizer_bands(&self) -> Vec<EqualizerBand>

The equalizer bands this backend has, centre frequency and range.

Empty where there is no equalizer, which is also what MediaCapabilities::equalizer reports. A backend states its real bands: a platform effect has the ones its implementation has, and a screen that wants a different layout maps onto these rather than being told a layout that is not there.

Source

fn set_equalizer(&self, _settings: &EqualizerSettings)

Applies an equalizer setting, already clamped to this backend’s bands.

Source

fn audio_extensions(&self) -> Vec<&'static str>

The audio file extensions this backend can decode, lower case and without the dot.

An application that picks tracks off a disk decides what to offer from this rather than from a list of its own. Which formats play is a property of the stack underneath — the platform’s decoders on a phone, the ones compiled in on a desktop — and a list written next to the picker is a claim about a backend it never asks. It goes stale the moment the backend changes, and the failure is quiet: the tracks import and then refuse to play.

Empty where the backend cannot say, which a caller should read as “no opinion, offer what you like” rather than as “nothing plays”.

Source

fn probe_duration(&self, _item: &MediaItem) -> Option<Duration>

Reads how long item is without opening it for playback.

A playlist shows the length of entries nobody has played yet, and the only thing that can answer is the stack that reads the container. None where this backend cannot tell, which is also what MediaCapabilities::probing reports; a screen leaves the duration blank rather than treating it as an error.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§