pub struct StaticSoundHandle { /* private fields */ }Expand description
Controls a static sound.
Implementations§
Source§impl StaticSoundHandle
impl StaticSoundHandle
Sourcepub fn state(&self) -> PlaybackState
pub fn state(&self) -> PlaybackState
Returns the current playback state of the sound.
Sourcepub fn set_volume(&mut self, volume: impl Into<Value<Decibels>>, tween: Tween)
pub fn set_volume(&mut self, volume: impl Into<Value<Decibels>>, tween: Tween)
Sets the volume of the sound.
§Examples
Set the volume of the sound immediately:
use kira::Tween;
sound.set_volume(-6.0, Tween::default());Smoothly transition the volume to a target volume:
use kira::Tween;
use std::time::Duration;
sound.set_volume(-6.0, Tween {
duration: Duration::from_secs(3),
..Default::default()
});Link the volume to a modulator, smoothly transitioning from the current value:
use kira::{
AudioManager, AudioManagerSettings, DefaultBackend,
sound::static_sound::{StaticSoundData, StaticSoundSettings},
modulator::tweener::TweenerBuilder,
Value, Tween, Mapping, Easing,
Decibels,
};
use std::time::Duration;
let mut manager = AudioManager::<DefaultBackend>::new(AudioManagerSettings::default())?;
let tweener = manager.add_modulator(TweenerBuilder {
initial_value: 0.5,
})?;
let mut sound = manager.play(StaticSoundData::from_file("sound.ogg")?)?;
sound.set_volume(Value::FromModulator {
id: tweener.id(),
mapping: Mapping {
input_range: (0.0, 1.0),
output_range: (Decibels::SILENCE, Decibels::IDENTITY),
easing: Easing::Linear,
}
}, Tween {
duration: Duration::from_secs(3),
..Default::default()
});Sourcepub fn set_playback_rate(
&mut self,
playback_rate: impl Into<Value<PlaybackRate>>,
tween: Tween,
)
pub fn set_playback_rate( &mut self, playback_rate: impl Into<Value<PlaybackRate>>, tween: Tween, )
Sets the playback rate of the sound.
Changing the playback rate will change both the speed and pitch of the sound.
§Examples
Set the playback rate of the sound immediately:
use kira::Tween;
sound.set_playback_rate(0.5, Tween::default());Smoothly transition the playback rate to a target value in semitones:
use kira::{Tween, Semitones};
use std::time::Duration;
sound.set_playback_rate(Semitones(-2.0), Tween {
duration: Duration::from_secs(3),
..Default::default()
});Link the playback rate to a modulator, smoothly transitioning from the current value:
use kira::{
AudioManager, AudioManagerSettings, DefaultBackend,
sound::static_sound::{StaticSoundData, StaticSoundSettings},
modulator::tweener::TweenerBuilder,
Value, Easing, Mapping, Tween,
PlaybackRate,
};
use std::time::Duration;
let mut manager = AudioManager::<DefaultBackend>::new(AudioManagerSettings::default())?;
let tweener = manager.add_modulator(TweenerBuilder {
initial_value: 0.5,
})?;
let mut sound = manager.play(StaticSoundData::from_file("sound.ogg")?)?;
sound.set_playback_rate(Value::FromModulator {
id: tweener.id(),
mapping: Mapping {
input_range: (0.0, 1.0),
output_range: (PlaybackRate(0.0), PlaybackRate(1.0)),
easing: Easing::Linear,
},
}, Tween {
duration: Duration::from_secs(3),
..Default::default()
});Sourcepub fn set_panning(&mut self, panning: impl Into<Value<Panning>>, tween: Tween)
pub fn set_panning(&mut self, panning: impl Into<Value<Panning>>, tween: Tween)
Sets the panning of the sound, where -1.0 is hard left,
0.0 is center, and 1.0 is hard right.
§Examples
Smoothly transition the panning to a target value:
use kira::Tween;
use std::time::Duration;
sound.set_panning(-0.5, Tween {
duration: Duration::from_secs(3),
..Default::default()
});Link the panning to a modulator, smoothly transitioning from the current value:
use kira::{
AudioManager, AudioManagerSettings, DefaultBackend,
sound::static_sound::{StaticSoundData, StaticSoundSettings},
modulator::tweener::TweenerBuilder,
Value, Easing, Mapping, Tween,
Panning,
};
use std::time::Duration;
let mut manager = AudioManager::<DefaultBackend>::new(AudioManagerSettings::default())?;
let tweener = manager.add_modulator(TweenerBuilder {
initial_value: -0.5,
})?;
let mut sound = manager.play(StaticSoundData::from_file("sound.ogg")?)?;
sound.set_panning(Value::FromModulator {
id: tweener.id(),
mapping: Mapping {
input_range: (-1.0, 1.0),
output_range: (Panning::LEFT, Panning::RIGHT),
easing: Easing::Linear,
},
}, Tween {
duration: Duration::from_secs(3),
..Default::default()
});Sourcepub fn set_loop_region(&mut self, loop_region: impl IntoOptionalRegion)
pub fn set_loop_region(&mut self, loop_region: impl IntoOptionalRegion)
Sets the portion of the sound that will play in a loop.
§Examples
Set the sound to loop the portion from 3 seconds in to the end:
sound.set_loop_region(3.0..);Set the sound to loop the portion from 2 to 4 seconds:
sound.set_loop_region(2.0..4.0);Set a sound that was previously looping to stop looping:
sound.set_loop_region(None);Sourcepub fn pause(&mut self, tween: Tween)
pub fn pause(&mut self, tween: Tween)
Fades out the sound to silence with the given tween and then pauses playback.
Sourcepub fn resume(&mut self, tween: Tween)
pub fn resume(&mut self, tween: Tween)
Resumes playback and fades in the sound from silence with the given tween.
Sourcepub fn resume_at(&mut self, start_time: StartTime, tween: Tween)
pub fn resume_at(&mut self, start_time: StartTime, tween: Tween)
Resumes playback at the given start time and fades in the sound from silence with the given tween.
Sourcepub fn stop(&mut self, tween: Tween)
pub fn stop(&mut self, tween: Tween)
Fades out the sound to silence with the given tween and then stops playback.
Once the sound is stopped, it cannot be restarted.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StaticSoundHandle
impl !RefUnwindSafe for StaticSoundHandle
impl Send for StaticSoundHandle
impl Sync for StaticSoundHandle
impl Unpin for StaticSoundHandle
impl UnsafeUnpin for StaticSoundHandle
impl !UnwindSafe for StaticSoundHandle
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
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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more