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.