[−][src]Crate riddle_audio
Riddle crate for loading and playing audio data.
Built largely on the back of ::image
and its dependencies.
Riddle Example
The recommended way to use this crate is through the main riddle
crate.
Riddle exposes this crate through riddle::audio
.
use riddle::*; fn main() -> Result<(), RiddleError> { let rdl = RiddleLib::new()?; // Load the clip let clip_bytes = include_bytes!("../../example_assets/boop.wav"); let clip = audio::Clip::new(&clip_bytes[..])?; // Play the clip let player = audio::ClipPlayerBuilder::new(&rdl.context().audio()) .play(&clip)?; let start_time = std::time::Instant::now(); rdl.run(move |rdl| { if std::time::Instant::now() - start_time > std::time::Duration::from_secs(2) { rdl.quit() } }) }
Direct Example
If you don't want to depend on riddle
, you can use this crate directly.
use riddle_audio::*; fn main() -> Result<(), AudioError> { let audio_system = AudioSystem::new()?; // Load the clip let clip_bytes = include_bytes!("../../example_assets/boop.wav"); let clip = Clip::new(&clip_bytes[..])?; // Play the clip let player = ClipPlayerBuilder::new(&audio_system) .play(&clip)?; // Let it play for two seconds let start_time = std::time::Instant::now(); while std::time::Instant::now() - start_time < std::time::Duration::from_secs(2) { audio_system.process_frame(); std::thread::sleep_ms(100); } Ok(()) }
Modules
doctest | DO NOT RELY ON THIS MODULE |
Structs
AudioSystem | The Riddle audio system core state. |
AudioSystemHandle | |
AudioSystemWeak | |
Clip | Stores the raw data of an audio file. |
ClipPlayer | Handles playback of a |
ClipPlayerBuilder | Builder for |
Enums
AudioError | |
PlayMode | Enum describing what the player should do at the end of the clip |