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§
Sourcefn preload(&self, data: &[u8]) -> Result<(), AudioError>
fn preload(&self, data: &[u8]) -> Result<(), AudioError>
Decodes data and rewinds to the start, without starting playback.
Sourcefn play(&self, source: &str, data: Option<&[u8]>) -> Result<(), AudioError>
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.
Sourcefn pause(&self) -> Result<(), AudioError>
fn pause(&self) -> Result<(), AudioError>
Pauses playback, preserving the current position.
Sourcefn resume(&self) -> Result<(), AudioError>
fn resume(&self) -> Result<(), AudioError>
Resumes playback from the current position.
Sourcefn current_seconds(&self) -> f32
fn current_seconds(&self) -> f32
The current playback position, in seconds.
Sourcefn duration_seconds(&self) -> f32
fn duration_seconds(&self) -> f32
The decoded duration in seconds, or 0.0 when nothing is loaded.
Sourcefn is_finished(&self) -> bool
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".