pub trait Audio {
// Required methods
fn music_playing(&self, now: Millis) -> Option<(&str, f64)>;
fn play(&mut self, frame: &AudioFrame<'_>, now: Millis);
fn stop_all(&mut self);
fn suspend(&mut self);
fn resume(&mut self);
// Provided method
fn voice_playing(&self, now: Millis) -> Option<&str> { ... }
}Expand description
A backend’s sound device.
Pausing. A backend that can pause a sound pauses it; one that
can’t mutes it (volume 0) and lets it run on silently. That holds for
SoundRequest::PauseSounds and for suspend. A
sound held either way keeps the volume it is given and sounds at it
when it is released, and music_playing says
where the track really is: a paused track’s clock holds, a muted one’s
runs.
Required Methods§
Sourcefn music_playing(&self, now: Millis) -> Option<(&str, f64)>
fn music_playing(&self, now: Millis) -> Option<(&str, f64)>
The music sounding at now: its cue and the seconds since it really
started (once its file had loaded), or None in silence: nothing
asked for, a track still loading or whose file failed. Of two
tracks sounding (a crossfade), the newest: the old one until the
new one has loaded.
Sourcefn play(&mut self, frame: &AudioFrame<'_>, now: Millis)
fn play(&mut self, frame: &AudioFrame<'_>, now: Millis)
Plays one frame’s frame of audio at now: the volumes first, then
the requests and the music commands in order. It also checks on
what is still loading, so it is called every frame, with nothing to
play too.
Sourcefn stop_all(&mut self)
fn stop_all(&mut self)
Stops the music, the voice and the sounds started with a handle: the game has quit.
Sourcefn suspend(&mut self)
fn suspend(&mut self)
Holds everything sounding (the sounds started with a handle, the
voice and the music) while the system suspends the game
(SystemEvent::Suspend); sound
cues played once finish. Pauses, or mutes where the backend can’t
pause. A second call does nothing.
It has no default: every backend says what it can hold (ADR-0056).
Sourcefn resume(&mut self)
fn resume(&mut self)
Brings back what suspend held, and leaves a
SoundRequest::PauseSounds pause in place. A call while not
suspended does nothing.
Provided Methods§
Sourcefn voice_playing(&self, now: Millis) -> Option<&str>
fn voice_playing(&self, now: Millis) -> Option<&str>
The voice clip sounding at now, by its file
(SoundRequest::Voice), or asked for and still loading: None
once it has ended, and for a clip stopped, replaced, whose file
failed or that loaded too late to be played. A clip held by
suspend still sounds. None by default, for a
device that plays no voices.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".