pub struct Player<B: Backend> { /* private fields */ }Expand description
The audio player: owns the decoded sounds and the music tracks.
Implementations§
Source§impl<B: Backend> Player<B>
impl<B: Backend> Player<B>
Sourcepub async fn load(
backend: &mut B,
manifest: AudioManifest,
files: &Files<'_>,
music_dir: String,
voice_dir: String,
seed: u64,
) -> Self
pub async fn load( backend: &mut B, manifest: AudioManifest, files: &Files<'_>, music_dir: String, voice_dir: String, seed: u64, ) -> Self
Readies every sound in manifest (reading its files through files,
the game’s own sounds). A sound that fails is left out with a warning.
Music tracks are looked for in music_dir and voice clips in
voice_dir. seed seeds the variant picker.
Sourcepub fn set_volumes(&mut self, backend: &mut B, music: f32, sound: f32)
pub fn set_volumes(&mut self, backend: &mut B, music: f32, sound: f32)
Sets the player’s volumes (the Options screen’s, 0–1): every sound and track plays at its own volume times these. A change reaches the tracks and the sounds started with a handle already playing.
Sourcepub fn suspend(&mut self, backend: &mut B)
pub fn suspend(&mut self, backend: &mut B)
Holds everything sounding while the system suspends the game: the sounds started with a handle, the voice and the music. It pauses them, or mutes them on a backend that can’t. Sounds played once finish. A second call does nothing.
Sourcepub fn resume(&mut self, backend: &mut B)
pub fn resume(&mut self, backend: &mut B)
Brings back what suspend held, at the volumes
asked for meanwhile; a sound paused under a menu stays held. A call
while not suspended does nothing.
Sourcepub fn play(
&mut self,
backend: &mut B,
requests: &[SoundRequest],
music: &[MusicCommand],
now: f64,
)
pub fn play( &mut self, backend: &mut B, requests: &[SoundRequest], music: &[MusicCommand], now: f64, )
Plays one frame’s sound and voice requests, applies the music
commands and checks on tracks and clips still loading. now is the
time in seconds on a clock that keeps running while the game isn’t
drawn (game ADR-0037): a track that starts in this call started at now.
Sourcepub fn music_playing(&self, now: f64) -> Option<(&str, f64)>
pub fn music_playing(&self, now: f64) -> Option<(&str, f64)>
The music sounding at now (on play’s clock): its
cue and the seconds since it started. None in silence, which
includes a track still loading or whose file failed. Of two tracks
(a crossfade) it is the newest that sounds: the old one until the
new one has loaded. A track played once is still reported after it has ended
(not every device says when it does; ui knows its length). A paused
track’s seconds hold; a muted one’s run on.
Sourcepub fn voice_playing(&self, now: f64) -> Option<&str>
pub fn voice_playing(&self, now: f64) -> Option<&str>
The file of the voice clip sounding at now (on
play’s clock), or asked for and still loading and
not yet late (0.3 s after it was asked for). None once it has ended, or was
stopped, failed or given up on. A paused clip still sounds; a clip
whose length the backend doesn’t know sounds until it is stopped.
Sourcepub fn stop_all(&mut self, backend: &mut B)
pub fn stop_all(&mut self, backend: &mut B)
Stops all music, the voice and the sounds started with a handle (the game quit, e.g. on the web page that stays open).
Sourcepub fn set_voice_volume(&mut self, backend: &mut B, volume: f32)
pub fn set_voice_volume(&mut self, backend: &mut B, volume: f32)
Sets how loud voice clips play (0–1; FrameOutput::voice_volume),
the one playing included.
Sourcepub fn set_rate(&mut self, backend: &mut B, cue: &str, rate: u32)
pub fn set_rate(&mut self, backend: &mut B, cue: &str, rate: u32)
Sets how fast sound cue plays from its next play, in 16.16 fixed
point (RATE_ONE as recorded). On a backend without a rate it plays
as recorded, and the log says so once.
Sourcepub fn take_warnings(&mut self) -> Vec<String>
pub fn take_warnings(&mut self) -> Vec<String>
Problems found since the last call, for the log.