pub struct SoundHandle { /* private fields */ }Expand description
Controls one playing sound instance, as returned by crate::Audio::play and friends.
Dropping the handle does not stop the sound; it keeps playing until it ends (or forever, if it loops). Clones refer to the same instance.
A handle can exist before the sound actually plays: a sound started with
crate::PlayOptions::deferred before audio is available (on the web, before the first
user gesture) is pending. Volume, pause and stop calls on a pending handle are remembered
and applied when the sound starts.
Implementations§
Source§impl SoundHandle
impl SoundHandle
Sourcepub fn set_volume(&self, volume: f32)
pub fn set_volume(&self, volume: f32)
Set the volume as a linear amplitude (1.0 is the sound’s own level, 0.0 silence).
Sourcepub fn set_volume_db(&self, db: f32)
pub fn set_volume_db(&self, db: f32)
Set the volume in decibels (0.0 is the sound’s own level, -6.0 roughly half).
Sourcepub fn fade_volume(&self, volume: f32, duration: Duration)
pub fn fade_volume(&self, volume: f32, duration: Duration)
Fade the volume to a linear amplitude over duration.
Sourcepub fn fade_volume_db(&self, db: f32, duration: Duration)
pub fn fade_volume_db(&self, db: f32, duration: Duration)
Fade the volume to db decibels over duration.
Sourcepub fn pause(&self)
pub fn pause(&self)
Pause playback. SoundHandle::resume continues where it left off.
Sourcepub fn stop(&self)
pub fn stop(&self)
Stop the sound for good. A stopped sound can’t be resumed; play it again instead.
Sourcepub fn is_playing(&self) -> bool
pub fn is_playing(&self) -> bool
Whether the sound is currently audible: playing, or fading in or out. false while
paused, pending or finished.
Sourcepub fn is_paused(&self) -> bool
pub fn is_paused(&self) -> bool
Whether the sound is paused (or will start paused, if pending).
Sourcepub fn is_pending(&self) -> bool
pub fn is_pending(&self) -> bool
Whether the sound is still waiting for audio to start (see crate::PlayOptions::deferred).
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Whether the sound has ended or was stopped. A looping sound only finishes when stopped.
Trait Implementations§
Source§impl Clone for SoundHandle
impl Clone for SoundHandle
Source§fn clone(&self) -> SoundHandle
fn clone(&self) -> SoundHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Forget for SoundHandle
impl Freeze for SoundHandle
impl RefUnwindSafe for SoundHandle
impl Send for SoundHandle
impl Sync for SoundHandle
impl Unpin for SoundHandle
impl UnsafeUnpin for SoundHandle
impl UnwindSafe for SoundHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.