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

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

Implementations§

source§

impl FilePlayer

source

pub fn load_into_player(&self, file_path: &str) -> Result<()>

Loads the given file into the player. Unlike with SamplePlayer, you must give the compiled audio filename here, e.g. “file.pda” instead of “file.wav”. MP3 files are not compiled, so they keep their original .mp3 extension.

source

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

Play the file ‘repeat_count’ times; if 0, play until stop is called. See set_loop_range for the portion of the file that will repeat.

source

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

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

source

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

Pause playback. To resume playback at the same point, use play().

source

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

Returns whether the player is currently playing the file.

source

pub fn set_buffer_length(&self, length: f32) -> Result<()>

How much audio to buffer, in seconds. Larger buffers use more memory but help avoid underruns, which can cause stuttering (see set_stop_on_underrun).

source

pub fn set_stop_on_underrun(&self, stop: bool) -> Result<()>

If set to true, and the buffer runs out of data (known as an underrun), the player will stop playing. If false (the default), the player will continue playback as soon as more data is available; this will come across as audio stuttering, particularly with small buffer sizes. (Note that Inside Playdate with C says the reverse, but seems wrong.)

source

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

Returns whether the buffer has underrun.

source

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

Returns the current offset into the file, in seconds, increasing as it plays.

source

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

Set how far into the file to start playing, in seconds.

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.

source

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

Sets the playback speed of the player; 1.0 is normal speed, 0.5 is down an octave, 2.0 is up one, etc.

source

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

Returns the length of the loaded file, in seconds.

Trait Implementations§

source§

impl Debug for FilePlayer

source§

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

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

impl Drop for FilePlayer

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.