Trait ggez::audio::SoundSource
source · pub trait SoundSource {
Show 18 methods
// Required methods
fn play_later(&self) -> GameResult;
fn play_detached(&mut self, audio: &impl Has<AudioContext>) -> GameResult;
fn set_repeat(&mut self, repeat: bool);
fn set_fade_in(&mut self, dur: Duration);
fn set_start(&mut self, dur: Duration);
fn set_pitch(&mut self, ratio: f32);
fn repeat(&self) -> bool;
fn pause(&self);
fn resume(&self);
fn stop(&mut self, audio: &impl Has<AudioContext>) -> GameResult;
fn stopped(&self) -> bool;
fn volume(&self) -> f32;
fn set_volume(&mut self, value: f32);
fn paused(&self) -> bool;
fn playing(&self) -> bool;
fn elapsed(&self) -> Duration;
fn set_query_interval(&mut self, t: Duration);
// Provided method
fn play(&mut self, audio: &impl Has<AudioContext>) -> GameResult { ... }
}
Expand description
A trait defining the operations possible on a sound;
it is implemented by both Source
and SpatialSource
.
Required Methods§
sourcefn play_later(&self) -> GameResult
fn play_later(&self) -> GameResult
Plays the SoundSource
; waits until done if the sound is currently playing
sourcefn play_detached(&mut self, audio: &impl Has<AudioContext>) -> GameResult
fn play_detached(&mut self, audio: &impl Has<AudioContext>) -> GameResult
Play source “in the background”; cannot be stopped
sourcefn set_repeat(&mut self, repeat: bool)
fn set_repeat(&mut self, repeat: bool)
Sets the source to repeat playback infinitely on next play()
sourcefn set_fade_in(&mut self, dur: Duration)
fn set_fade_in(&mut self, dur: Duration)
Sets the fade-in time of the source
sourcefn set_start(&mut self, dur: Duration)
fn set_start(&mut self, dur: Duration)
Sets the time from which playback begins, skipping audio up to that point.
Calls to elapsed()
will measure from this point, ignoring skipped time.
Effects such as set_fade_in()
or set_pitch()
will apply from this new start.
If set_repeat()
is set to true, then after looping, the audio will return
to the original beginning of the source, rather than the time specified here.
sourcefn stop(&mut self, audio: &impl Has<AudioContext>) -> GameResult
fn stop(&mut self, audio: &impl Has<AudioContext>) -> GameResult
Stops playback
sourcefn stopped(&self) -> bool
fn stopped(&self) -> bool
Returns whether or not the source is stopped – that is, has no more data to play.
sourcefn set_volume(&mut self, value: f32)
fn set_volume(&mut self, value: f32)
Sets the current volume.
sourcefn playing(&self) -> bool
fn playing(&self) -> bool
Get whether or not the source is playing (ie, not paused and not stopped).
sourcefn elapsed(&self) -> Duration
fn elapsed(&self) -> Duration
Get the time the source has been playing since the last call to play()
.
Time measurement is based on audio samples consumed, so it may drift from the system
sourcefn set_query_interval(&mut self, t: Duration)
fn set_query_interval(&mut self, t: Duration)
Set the update interval of the internal sample counter.
This parameter determines the precision of the time measured by elapsed()
.
Provided Methods§
sourcefn play(&mut self, audio: &impl Has<AudioContext>) -> GameResult
fn play(&mut self, audio: &impl Has<AudioContext>) -> GameResult
Plays the audio source; restarts the sound if currently playing