Struct Sink
pub struct Sink { /* private fields */ }
dep_rodio
only.Expand description
Handle to a device that outputs sounds.
Dropping the Sink
stops all sounds. You can use detach
if you want the sounds to continue
playing.
Implementations§
§impl Sink
impl Sink
pub fn try_new(stream: &OutputStreamHandle) -> Result<Sink, PlayError> ⓘ
pub fn try_new(stream: &OutputStreamHandle) -> Result<Sink, PlayError> ⓘ
Builds a new Sink
, beginning playback on a stream.
pub fn new_idle() -> (Sink, SourcesQueueOutput<f32>) ⓘ
pub fn new_idle() -> (Sink, SourcesQueueOutput<f32>) ⓘ
Builds a new Sink
.
pub fn append<S>(&self, source: S)
pub fn append<S>(&self, source: S)
Appends a sound to the queue of sounds to play.
pub fn volume(&self) -> f32 ⓘ
pub fn volume(&self) -> f32 ⓘ
Gets the volume of the sound.
The value 1.0
is the “normal” volume (unfiltered input). Any value other than 1.0 will
multiply each sample by this value.
pub fn set_volume(&self, value: f32)
pub fn set_volume(&self, value: f32)
Changes the volume of the sound.
The value 1.0
is the “normal” volume (unfiltered input). Any value other than 1.0
will
multiply each sample by this value.
pub fn speed(&self) -> f32 ⓘ
pub fn speed(&self) -> f32 ⓘ
Changes the play speed of the sound. Does not adjust the samples, only the playback speed.
§Note:
- Increasing the speed will increase the pitch by the same factor
- If you set the speed to 0.5 this will halve the frequency of the sound lowering its pitch.
- If you set the speed to 2 the frequency will double raising the pitch of the sound.
- Change in the speed affect the total duration inversely
- If you set the speed to 0.5, the total duration will be twice as long.
- If you set the speed to 2 the total duration will be halve of what it was.
See [Speed
] for details
pub fn set_speed(&self, value: f32)
pub fn set_speed(&self, value: f32)
Changes the speed of the sound.
The value 1.0
is the “normal” speed (unfiltered input). Any value other than 1.0
will
change the play speed of the sound.
§Note:
- Increasing the speed would also increase the pitch by the same factor
- If you increased set the speed to 0.5, the frequency would be slower (0.5x the original frequency) .
- Also if you set the speed to 1.5 the frequency would be faster ( 1.5x the original frequency).
- Change in the speed would affect your total duration inversely
- if you set the speed by 0.5, your total duration would be (2x the original total duration) longer.
- Also if you set the speed to 2 the total duration would be (0.5 the original total_duration) shorter
pub fn play(&self)
pub fn play(&self)
Resumes playback of a paused sink.
No effect if not paused.
pub fn try_seek(&self, pos: Duration) -> Result<(), SeekError> ⓘ
pub fn try_seek(&self, pos: Duration) -> Result<(), SeekError> ⓘ
Attempts to seek to a given position in the current source.
This blocks between 0 and ~5 milliseconds.
As long as the duration of the source is known, seek is guaranteed to saturate
at the end of the source. For example given a source that reports a total duration
of 42 seconds calling try_seek()
with 60 seconds as argument will seek to
42 seconds.
§Errors
This function will return SeekError::NotSupported
if one of the underlying
sources does not support seeking.
It will return an error if an implementation ran into one during the seek.
When seeking beyond the end of a source this function might return an error if the duration of the source is not known.
pub fn pause(&self)
pub fn pause(&self)
Pauses playback of this sink.
No effect if already paused.
A paused sink can be resumed with play()
.
pub fn is_paused(&self) -> bool
pub fn is_paused(&self) -> bool
Gets if a sink is paused
Sinks can be paused and resumed using pause()
and play()
. This returns true
if the
sink is paused.
pub fn clear(&self)
pub fn clear(&self)
Removes all currently loaded Source
s from the Sink
, and pauses it.
See pause()
for information about pausing a Sink
.
pub fn skip_one(&self)
pub fn skip_one(&self)
Skips to the next Source
in the Sink
If there are more Source
s appended to the Sink
at the time,
it will play the next one. Otherwise, the Sink
will finish as if
it had finished playing a Source
all the way through.
pub fn stop(&self)
pub fn stop(&self)
Stops the sink by emptying the queue.
pub fn detach(self)
pub fn detach(self)
Destroys the sink without stopping the sounds that are still playing.
pub fn sleep_until_end(&self)
pub fn sleep_until_end(&self)
Sleeps the current thread until the sound ends.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Sink
impl RefUnwindSafe for Sink
impl Send for Sink
impl Sync for Sink
impl Unpin for Sink
impl UnwindSafe for Sink
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.