Struct crankstart::sound::fileplayer::FilePlayer
source · 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
impl FilePlayer
sourcepub fn load_into_player(&self, file_path: &str) -> Result<()>
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.
sourcepub fn play(&self, repeat_count: c_int) -> Result<()>
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.
sourcepub fn stop(&self) -> Result<()>
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.
sourcepub fn pause(&self) -> Result<()>
pub fn pause(&self) -> Result<()>
Pause playback. To resume playback at the same point, use play().
sourcepub fn is_playing(&self) -> Result<bool>
pub fn is_playing(&self) -> Result<bool>
Returns whether the player is currently playing the file.
sourcepub fn set_buffer_length(&self, length: f32) -> Result<()>
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).
sourcepub fn set_stop_on_underrun(&self, stop: bool) -> Result<()>
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.)
sourcepub fn did_underrun(&self) -> Result<bool>
pub fn did_underrun(&self) -> Result<bool>
Returns whether the buffer has underrun.
sourcepub fn get_offset(&self) -> Result<f32>
pub fn get_offset(&self) -> Result<f32>
Returns the current offset into the file, in seconds, increasing as it plays.
sourcepub fn set_offset(&self, offset: f32) -> Result<()>
pub fn set_offset(&self, offset: f32) -> Result<()>
Set how far into the file to start playing, in seconds.
sourcepub fn get_volume(&self) -> Result<(f32, f32)>
pub fn get_volume(&self) -> Result<(f32, f32)>
Gets the current volume of the left and right audio channels, out of 1.
sourcepub fn set_volume(&self, left: f32, right: f32) -> Result<()>
pub fn set_volume(&self, left: f32, right: f32) -> Result<()>
Sets the volume of the left and right audio channels, out of 1.
sourcepub fn set_rate(&self, playback_speed: f32) -> Result<()>
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.
sourcepub fn get_length(&self) -> Result<f32>
pub fn get_length(&self) -> Result<f32>
Returns the length of the loaded file, in seconds.