Struct rodio::Sink

source ·
pub struct Sink { /* private fields */ }
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§

source§

impl Sink

source

pub fn try_new(stream: &OutputStreamHandle) -> Result<Sink, PlayError>

Builds a new Sink, beginning playback on a stream.

source

pub fn new_idle() -> (Sink, SourcesQueueOutput<f32>)

Builds a new Sink.

source

pub fn append<S>(&self, source: S)
where S: Source + Send + 'static, f32: FromSample<S::Item>, S::Item: Sample + Send,

Appends a sound to the queue of sounds to play.

source

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.

source

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.

source

pub fn speed(&self) -> f32

Changes the play speed of the sound. Does not adjust the samples, only the playback speed.

§Note:
  1. 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.
  1. 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

source

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:
  1. 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).
  1. 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
source

pub fn play(&self)

Resumes playback of a paused sink.

No effect if not paused.

source

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.

source

pub fn pause(&self)

Pauses playback of this sink.

No effect if already paused.

A paused sink can be resumed with play().

source

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.

source

pub fn clear(&self)

Removes all currently loaded Sources from the Sink, and pauses it.

See pause() for information about pausing a Sink.

source

pub fn skip_one(&self)

Skips to the next Source in the Sink

If there are more Sources 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.

source

pub fn stop(&self)

Stops the sink by emptying the queue.

source

pub fn detach(self)

Destroys the sink without stopping the sounds that are still playing.

source

pub fn sleep_until_end(&self)

Sleeps the current thread until the sound ends.

source

pub fn empty(&self) -> bool

Returns true if this sink has no more sounds to play.

source

pub fn len(&self) -> usize

Returns the number of sounds currently in the queue.

source

pub fn get_pos(&self) -> Duration

Returns the position of the sound that’s being played.

This takes into account any speedup or delay applied.

Example: if you apply a speedup of 2 to an mp3 decoder source and get_pos() returns 5s then the position in the mp3 recording is 10s from its start.

Trait Implementations§

source§

impl Drop for Sink

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<S> FromSample<S> for S

source§

fn from_sample_(s: S) -> S

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

source§

fn into_sample(self) -> T

source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

source§

fn to_sample_(self) -> U

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,