pub struct StreamingSoundHandle<Error> { /* private fields */ }Expand description
Controls a streaming sound.
Implementations§
Source§impl<Error> StreamingSoundHandle<Error>
impl<Error> StreamingSoundHandle<Error>
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<Volume>>,
tween: Tween,
) -> Result<(), CommandError>
pub fn set_volume( &mut self, volume: impl Into<Value<Volume>>, tween: Tween, ) -> Result<(), CommandError>
Sets the volume of the sound.
§Examples
Set the volume of the sound as a factor immediately:
use kira::tween::Tween;
sound.set_volume(0.5, Tween::default())?;Smoothly transition the volume to a target value in decibels:
use kira::tween::Tween;
use std::time::Duration;
sound.set_volume(kira::Volume::Decibels(-6.0), Tween {
duration: Duration::from_secs(3),
..Default::default()
})?;Link the volume to a modulator, smoothly transitioning from the current value:
use kira::{
manager::{AudioManager, AudioManagerSettings, backend::DefaultBackend},
sound::streaming::{StreamingSoundData, StreamingSoundSettings},
modulator::tweener::TweenerBuilder,
tween::Tween,
};
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(StreamingSoundData::from_file("sound.ogg", StreamingSoundSettings::default())?)?;
sound.set_volume(&tweener, Tween {
duration: Duration::from_secs(3),
..Default::default()
})?;Sourcepub fn set_playback_rate(
&mut self,
playback_rate: impl Into<Value<PlaybackRate>>,
tween: Tween,
) -> Result<(), CommandError>
pub fn set_playback_rate( &mut self, playback_rate: impl Into<Value<PlaybackRate>>, tween: Tween, ) -> Result<(), CommandError>
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 as a factor immediately:
use kira::tween::Tween;
sound.set_playback_rate(0.5, Tween::default())?;Smoothly transition the playback rate to a target value in semitones:
use kira::{
tween::Tween,
sound::PlaybackRate,
};
use std::time::Duration;
sound.set_playback_rate(PlaybackRate::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::{
manager::{AudioManager, AudioManagerSettings, backend::DefaultBackend},
sound::streaming::{StreamingSoundData, StreamingSoundSettings},
modulator::tweener::TweenerBuilder,
tween::Tween,
};
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(StreamingSoundData::from_file("sound.ogg", StreamingSoundSettings::default())?)?;
sound.set_playback_rate(&tweener, Tween {
duration: Duration::from_secs(3),
..Default::default()
})?;Sourcepub fn set_panning(
&mut self,
panning: impl Into<Value<f64>>,
tween: Tween,
) -> Result<(), CommandError>
pub fn set_panning( &mut self, panning: impl Into<Value<f64>>, tween: Tween, ) -> Result<(), CommandError>
Sets the panning of the sound, where 0.0 is hard left,
0.5 is center, and 1.0 is hard right.
§Examples
Smoothly transition the panning to a target value:
use kira::tween::Tween;
use std::time::Duration;
sound.set_panning(0.25, Tween {
duration: Duration::from_secs(3),
..Default::default()
})?;Link the panning to a modulator, smoothly transitioning from the current value:
use kira::{
manager::{AudioManager, AudioManagerSettings, backend::DefaultBackend},
sound::streaming::{StreamingSoundData, StreamingSoundSettings},
modulator::tweener::TweenerBuilder,
tween::Tween,
};
use std::time::Duration;
let mut manager = AudioManager::<DefaultBackend>::new(AudioManagerSettings::default())?;
let tweener = manager.add_modulator(TweenerBuilder {
initial_value: 0.25,
})?;
let mut sound = manager.play(StreamingSoundData::from_file("sound.ogg", StreamingSoundSettings::default())?)?;
sound.set_panning(&tweener, Tween {
duration: Duration::from_secs(3),
..Default::default()
})?;Sourcepub fn set_playback_region(
&mut self,
playback_region: impl Into<Region>,
) -> Result<(), CommandError>
pub fn set_playback_region( &mut self, playback_region: impl Into<Region>, ) -> Result<(), CommandError>
Sets the portion of the sound that should be played.
§Examples
Set the sound to play from 3 seconds in to the end:
sound.set_playback_region(3.0..)?;Set the sound to play from 2 to 4 seconds:
sound.set_playback_region(2.0..4.0)?;Sourcepub fn set_loop_region(
&mut self,
loop_region: impl IntoOptionalRegion,
) -> Result<(), CommandError>
pub fn set_loop_region( &mut self, loop_region: impl IntoOptionalRegion, ) -> Result<(), CommandError>
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) -> Result<(), CommandError>
pub fn pause(&mut self, tween: Tween) -> Result<(), CommandError>
Fades out the sound to silence with the given tween and then pauses playback.
Sourcepub fn resume(&mut self, tween: Tween) -> Result<(), CommandError>
pub fn resume(&mut self, tween: Tween) -> Result<(), CommandError>
Resumes playback and fades in the sound from silence with the given tween.
Sourcepub fn stop(&mut self, tween: Tween) -> Result<(), CommandError>
pub fn stop(&mut self, tween: Tween) -> Result<(), CommandError>
Fades out the sound to silence with the given tween and then stops playback.
Once the sound is stopped, it cannot be restarted.
Sourcepub fn seek_to(&mut self, position: f64) -> Result<(), CommandError>
pub fn seek_to(&mut self, position: f64) -> Result<(), CommandError>
Sets the playback position to the specified time in seconds.
Auto Trait Implementations§
impl<Error> Freeze for StreamingSoundHandle<Error>
impl<Error> RefUnwindSafe for StreamingSoundHandle<Error>where
Error: RefUnwindSafe,
impl<Error> Send for StreamingSoundHandle<Error>where
Error: Send,
impl<Error> Sync for StreamingSoundHandle<Error>
impl<Error> Unpin for StreamingSoundHandle<Error>where
Error: Unpin,
impl<Error> UnwindSafe for StreamingSoundHandle<Error>where
Error: UnwindSafe + RefUnwindSafe,
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<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
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