pub trait Backend {
type Sound;
type Loading;
type Playing;
Show 17 methods
// Required methods
fn load_sound(
&mut self,
bytes: &[u8],
) -> impl Future<Output = Result<Self::Sound, String>>;
fn load_music(&mut self, path: &str) -> Self::Loading;
fn poll_music(
&mut self,
loading: &mut Self::Loading,
) -> Option<Result<Self::Sound, String>>;
fn length(&self, sound: &Self::Sound) -> Option<f64>;
fn play(
&mut self,
sound: &Self::Sound,
volume: f32,
looped: bool,
) -> Self::Playing;
fn set_volume(&mut self, sound: &Self::Sound, volume: f32);
fn stop(&mut self, sound: &Self::Sound);
fn set_playing_volume(&mut self, playing: &Self::Playing, volume: f32);
fn stop_playing(&mut self, playing: Self::Playing);
// Provided methods
fn load_sound_file(
&mut self,
file: &str,
files: &Files<'_>,
) -> impl Future<Output = Result<Self::Sound, String>> { ... }
fn pause(&mut self, playing: &Self::Playing) -> Result<(), Unsupported> { ... }
fn resume(&mut self, playing: &Self::Playing) -> Result<(), Unsupported> { ... }
fn set_rate(
&mut self,
sound: &Self::Sound,
rate: u32,
) -> Result<(), Unsupported> { ... }
fn add_sound(
&mut self,
samples: &SharedSamples,
) -> Result<Self::Sound, String> { ... }
fn remove_sound(&mut self, sound: Self::Sound) { ... }
fn hold_output(&mut self, on: bool) { ... }
fn warn(&mut self, _line: &str) { ... }
}Expand description
What playing audio needs from the platform: all a backend writes for the sound of a game (ADR-0063).
A feature some backends lack is a provided method, whose default does
nothing and says Unsupported, so that adding one breaks no backend.
Required Associated Types§
Required Methods§
Sourcefn load_sound(
&mut self,
bytes: &[u8],
) -> impl Future<Output = Result<Self::Sound, String>>
fn load_sound( &mut self, bytes: &[u8], ) -> impl Future<Output = Result<Self::Sound, String>>
Decodes a sound file’s bytes.
Sourcefn load_music(&mut self, path: &str) -> Self::Loading
fn load_music(&mut self, path: &str) -> Self::Loading
Starts loading and decoding the music or voice file at path.
Sourcefn poll_music(
&mut self,
loading: &mut Self::Loading,
) -> Option<Result<Self::Sound, String>>
fn poll_music( &mut self, loading: &mut Self::Loading, ) -> Option<Result<Self::Sound, String>>
The track, once loading has finished (called once per frame).
Sourcefn length(&self, sound: &Self::Sound) -> Option<f64>
fn length(&self, sound: &Self::Sound) -> Option<f64>
How long sound plays, in seconds, if that is known: it is for an
OGG file loaded with load_music.
Sourcefn play(
&mut self,
sound: &Self::Sound,
volume: f32,
looped: bool,
) -> Self::Playing
fn play( &mut self, sound: &Self::Sound, volume: f32, looped: bool, ) -> Self::Playing
Plays sound from the start at volume (0–1): this playback.
Sourcefn set_volume(&mut self, sound: &Self::Sound, volume: f32)
fn set_volume(&mut self, sound: &Self::Sound, volume: f32)
Changes the volume of sound wherever it plays.
Sourcefn set_playing_volume(&mut self, playing: &Self::Playing, volume: f32)
fn set_playing_volume(&mut self, playing: &Self::Playing, volume: f32)
Changes the volume of playing alone.
Sourcefn stop_playing(&mut self, playing: Self::Playing)
fn stop_playing(&mut self, playing: Self::Playing)
Stops playing alone: other copies of its sound play on.
Provided Methods§
Sourcefn load_sound_file(
&mut self,
file: &str,
files: &Files<'_>,
) -> impl Future<Output = Result<Self::Sound, String>>
fn load_sound_file( &mut self, file: &str, files: &Files<'_>, ) -> impl Future<Output = Result<Self::Sound, String>>
Readies the sound file file of the manifest. By default it reads
the file with files and decodes it with
load_sound; a device that loads a sound from
its own path says so here.
Sourcefn pause(&mut self, playing: &Self::Playing) -> Result<(), Unsupported>
fn pause(&mut self, playing: &Self::Playing) -> Result<(), Unsupported>
Stops playing so that resume goes on from where
it was. Without it the player mutes the sound, which runs on silently.
Sourcefn resume(&mut self, playing: &Self::Playing) -> Result<(), Unsupported>
fn resume(&mut self, playing: &Self::Playing) -> Result<(), Unsupported>
Goes on with playing from where pause stopped it.
Sourcefn add_sound(&mut self, samples: &SharedSamples) -> Result<Self::Sound, String>
fn add_sound(&mut self, samples: &SharedSamples) -> Result<Self::Sound, String>
Readies samples, samples a game made at run time, as a sound to play
like one loaded from a file. By default it can’t, and the cue plays
nothing, with a warning in the log.
Sourcefn remove_sound(&mut self, sound: Self::Sound)
fn remove_sound(&mut self, sound: Self::Sound)
Lets go of sound, which add_sound made: it
stops wherever it plays and its memory is freed. By default it is
stopped and dropped.
Sourcefn hold_output(&mut self, on: bool)
fn hold_output(&mut self, on: bool)
The system suspends the game (on) or has resumed it: a backend whose output
can stop stops it here, after the player has held what sounds.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".