Struct StreamingSoundHandle
pub struct StreamingSoundHandle<Error> { /* private fields */ }
dep_kira
only.Expand description
Controls a streaming sound.
Implementations§
§impl<Error> StreamingSoundHandle<Error>
impl<Error> StreamingSoundHandle<Error>
pub fn state(&self) -> PlaybackState
pub fn state(&self) -> PlaybackState
Returns the current playback state of the sound.
pub 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::streaming::{StreamingSoundData, StreamingSoundSettings},
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(StreamingSoundData::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()
});
pub 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::streaming::{StreamingSoundData, StreamingSoundSettings},
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(StreamingSoundData::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()
});
pub 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::streaming::{StreamingSoundData, StreamingSoundSettings},
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(StreamingSoundData::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()
});
pub 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);
pub 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.
pub 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.
pub 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.
pub 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.
pub fn seek_to(&mut self, position: f64)
pub fn seek_to(&mut self, position: f64)
Sets the playback position to the specified time in seconds.
Trait Implementations§
Auto Trait Implementations§
impl<Error> !Freeze for StreamingSoundHandle<Error>
impl<Error> !RefUnwindSafe for StreamingSoundHandle<Error>
impl<Error> Send for StreamingSoundHandle<Error>where
Error: Send,
impl<Error> !Sync for StreamingSoundHandle<Error>
impl<Error> Unpin for StreamingSoundHandle<Error>
impl<Error> !UnwindSafe for StreamingSoundHandle<Error>
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize ⓘ
fn byte_align(&self) -> usize ⓘ
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> ExtAny for T
impl<T> ExtAny for T
Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of_val(&self) -> usize ⓘ
fn mem_align_of_val(&self) -> usize ⓘ
Source§fn mem_size_of_val(&self) -> usize ⓘ
fn mem_size_of_val(&self) -> usize ⓘ
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true
if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self
without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice
only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError> ⓘ
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError> ⓘ
§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out
indicating that a T
is niched.