pub struct SamplePlayer { /* private fields */ }
Expand description

Note: Make sure you hold on to a SamplePlayer until the sample has played as much as you want, because dropping it will stop playback.

Implementations§

source§

impl SamplePlayer

source

pub fn set_sample(&mut self, audio_sample: &AudioSample) -> Result<()>

Sets the sound effect to be played by this player.

source

pub fn play(&self, repeat_count: c_int, playback_speed: f32) -> Result<()>

Play the sample ‘repeat_count’ times; if 0, play until stop is called; if -1, play forward, backward, forward, etc. (See set_play_range to change which part is looped.) ‘playback_speed’ is how fast the sample plays; 1.0 is normal speed, 0.5 is down an octave, 2.0 is up one, etc. A negative rate plays the sample in reverse.

source

pub fn stop(&self) -> Result<()>

Can be used to stop a sample early, or stop one that’s repeating endlessly because ‘repeat’ was set to 0.

source

pub fn set_paused(&self, paused: bool) -> Result<()>

Pause or resume playback.

source

pub fn is_playing(&self) -> Result<bool>

Returns whether the player is currently playing the sample.

source

pub fn set_play_range(&self, start: c_int, end: c_int) -> Result<()>

Sets the start and end position, in frames, when looping a sample with repeat_count -1.

source

pub fn get_offset(&self) -> Result<f32>

Returns the current offset into the sample, in seconds, increasing as it plays. This is not adjusted for rate.

source

pub fn set_offset(&self, offset: f32) -> Result<()>

Set how far into the sample to start playing, in seconds. This is not adjusted for rate.

source

pub fn get_volume(&self) -> Result<(f32, f32)>

Gets the current volume of the left and right audio channels, out of 1.

source

pub fn set_volume(&self, left: f32, right: f32) -> Result<()>

Sets the volume of the left and right audio channels, out of 1.

source

pub fn get_rate(&self) -> Result<f32>

Gets the current playback speed. Returns 1 unless the value was changed by set_rate - it still returns 1 if the rate is changed with the argument to play.

source

pub fn set_rate(&self, playback_speed: f32) -> Result<()>

Sets the playback speed of the player after a sample has started playing. 1.0 is normal, 0.5 is down an octave, 2.0 is up one, etc. A negative rate plays the sample in reverse.

source

pub fn get_length(&self) -> Result<f32>

Returns the length of the assigned sample, in seconds.

Trait Implementations§

source§

impl Debug for SamplePlayer

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for SamplePlayer

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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<T, U> Into<U> for Twhere 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<T> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.