Skip to main content

AudioSink

Trait AudioSink 

Source
pub trait AudioSink: Send + Sync {
    // Required methods
    fn preload(&self, data: &[u8]) -> Result<(), AudioError>;
    fn play(&self, source: &str, data: Option<&[u8]>) -> Result<(), AudioError>;
    fn pause(&self) -> Result<(), AudioError>;
    fn resume(&self) -> Result<(), AudioError>;
    fn current_seconds(&self) -> f32;
    fn duration_seconds(&self) -> f32;
    fn is_finished(&self) -> bool;
}
Expand description

A single playable audio source.

Implementations own whatever playback state the platform needs, so a sink is not shared between two <audio> elements — use AudioSinkFactory to obtain one instance per element.

Required Methods§

Source

fn preload(&self, data: &[u8]) -> Result<(), AudioError>

Decodes data and rewinds to the start, without starting playback.

Source

fn play(&self, source: &str, data: Option<&[u8]>) -> Result<(), AudioError>

Starts playback of source, restarting from the beginning if the source is not currently playing.

data carries the already-fetched media bytes when they are available. Sources that the platform must resolve itself (for example file: or resource: URIs) may ignore data and load source.

Source

fn pause(&self) -> Result<(), AudioError>

Pauses playback, preserving the current position.

Source

fn resume(&self) -> Result<(), AudioError>

Resumes playback from the current position.

Source

fn current_seconds(&self) -> f32

The current playback position, in seconds.

Source

fn duration_seconds(&self) -> f32

The decoded duration in seconds, or 0.0 when nothing is loaded.

Source

fn is_finished(&self) -> bool

Whether the decoded source reached its end.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§