Skip to main content

AudioPlayer

Trait AudioPlayer 

Source
pub trait AudioPlayer {
Show 18 methods // Required methods fn load_clip(&self, clip: AudioClip) -> Result<SoundId, AudioError>; fn play(&self, id: SoundId, params: PlaybackParams); fn play_loop(&self, id: SoundId, params: PlaybackParams) -> VoiceId; fn stop(&self, id: SoundId); fn stop_voice(&self, voice: VoiceId); fn set_master_volume(&self, volume: f32); // Provided methods fn load(&self, bytes: &[u8]) -> Result<SoundId, AudioError> { ... } fn unload(&self, _id: SoundId) { ... } fn stop_all(&self) { ... } fn set_voice_params(&self, _voice: VoiceId, _params: PlaybackParams) { ... } fn master_volume(&self) -> f32 { ... } fn set_bus_volume(&self, _bus: AudioBus, _volume: f32) { ... } fn bus_volume(&self, _bus: AudioBus) -> f32 { ... } fn set_bus_enabled(&self, _bus: AudioBus, _enabled: bool) { ... } fn bus_enabled(&self, _bus: AudioBus) -> bool { ... } fn suspend(&self) { ... } fn resume(&self) { ... } fn is_available(&self) -> bool { ... }
}
Expand description

Plays sound. Installed by the platform backend; the default is a no-op.

Only load_clip, play, play_loop, stop, stop_voice and set_master_volume must be implemented; everything else has a defaulted body so a partial backend still compiles.

Required Methods§

Source

fn load_clip(&self, clip: AudioClip) -> Result<SoundId, AudioError>

Hands an already-decoded clip to the engine.

Source

fn play(&self, id: SoundId, params: PlaybackParams)

Starts a one-shot voice. Re-triggering the same clip layers a new voice rather than restarting the old one.

Source

fn play_loop(&self, id: SoundId, params: PlaybackParams) -> VoiceId

Starts a looping voice and returns its handle.

Source

fn stop(&self, id: SoundId)

Stops every voice playing id.

Source

fn stop_voice(&self, voice: VoiceId)

Stops one voice.

Source

fn set_master_volume(&self, volume: f32)

Sets the gain applied to every bus.

Provided Methods§

Source

fn load(&self, bytes: &[u8]) -> Result<SoundId, AudioError>

Decodes bytes and loads the result.

Decoding happens here, on the calling thread, so that play is only a queue push. To keep even the load off the UI thread, decode with AudioClip::decode elsewhere and call load_clip.

Source

fn unload(&self, _id: SoundId)

Releases a clip. Voices already playing it are stopped.

Source

fn stop_all(&self)

Stops every voice on every bus.

Source

fn set_voice_params(&self, _voice: VoiceId, _params: PlaybackParams)

Retunes a voice while it plays — a looping engine note that follows speed, for instance.

Source

fn master_volume(&self) -> f32

The current master gain.

Source

fn set_bus_volume(&self, _bus: AudioBus, _volume: f32)

Sets one bus’s gain.

Source

fn bus_volume(&self, _bus: AudioBus) -> f32

One bus’s gain.

Source

fn set_bus_enabled(&self, _bus: AudioBus, _enabled: bool)

Mutes or unmutes a bus. This is the “sound on” / “music on” toggle; muting leaves voices running so unmuting resumes mid-track.

Source

fn bus_enabled(&self, _bus: AudioBus) -> bool

Whether a bus is audible.

Source

fn suspend(&self)

Releases the output device without discarding loaded clips — call it when the app goes to the background.

Source

fn resume(&self)

Re-acquires the output device after suspend.

Source

fn is_available(&self) -> bool

Whether a real device is behind this handle. The no-op default reports false, so an app can honestly grey out its audio settings.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§