Skip to main content

Player

Struct Player 

Source
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>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

pub fn take_warnings(&mut self) -> Vec<String>

Problems found since the last call, for the log.

Auto Trait Implementations§

§

impl<B> Freeze for Player<B>
where <B as Backend>::Playing: Freeze,

§

impl<B> RefUnwindSafe for Player<B>

§

impl<B> Send for Player<B>
where <B as Backend>::Sound: Send, <B as Backend>::Loading: Send, <B as Backend>::Playing: Send,

§

impl<B> Sync for Player<B>
where <B as Backend>::Sound: Sync, <B as Backend>::Loading: Sync, <B as Backend>::Playing: Sync,

§

impl<B> Unpin for Player<B>
where <B as Backend>::Loading: Unpin, <B as Backend>::Playing: Unpin,

§

impl<B> UnsafeUnpin for Player<B>
where <B as Backend>::Playing: UnsafeUnpin,

§

impl<B> UnwindSafe for Player<B>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.