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§
Sourcefn load_clip(&self, clip: AudioClip) -> Result<SoundId, AudioError>
fn load_clip(&self, clip: AudioClip) -> Result<SoundId, AudioError>
Hands an already-decoded clip to the engine.
Sourcefn play(&self, id: SoundId, params: PlaybackParams)
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.
Sourcefn play_loop(&self, id: SoundId, params: PlaybackParams) -> VoiceId
fn play_loop(&self, id: SoundId, params: PlaybackParams) -> VoiceId
Starts a looping voice and returns its handle.
Sourcefn stop_voice(&self, voice: VoiceId)
fn stop_voice(&self, voice: VoiceId)
Stops one voice.
Sourcefn set_master_volume(&self, volume: f32)
fn set_master_volume(&self, volume: f32)
Sets the gain applied to every bus.
Provided Methods§
Sourcefn load(&self, bytes: &[u8]) -> Result<SoundId, AudioError>
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.
Sourcefn set_voice_params(&self, _voice: VoiceId, _params: PlaybackParams)
fn set_voice_params(&self, _voice: VoiceId, _params: PlaybackParams)
Retunes a voice while it plays — a looping engine note that follows speed, for instance.
Sourcefn master_volume(&self) -> f32
fn master_volume(&self) -> f32
The current master gain.
Sourcefn set_bus_volume(&self, _bus: AudioBus, _volume: f32)
fn set_bus_volume(&self, _bus: AudioBus, _volume: f32)
Sets one bus’s gain.
Sourcefn bus_volume(&self, _bus: AudioBus) -> f32
fn bus_volume(&self, _bus: AudioBus) -> f32
One bus’s gain.
Sourcefn set_bus_enabled(&self, _bus: AudioBus, _enabled: bool)
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.
Sourcefn bus_enabled(&self, _bus: AudioBus) -> bool
fn bus_enabled(&self, _bus: AudioBus) -> bool
Whether a bus is audible.
Sourcefn suspend(&self)
fn suspend(&self)
Releases the output device without discarding loaded clips — call it when the app goes to the background.
Sourcefn is_available(&self) -> bool
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".