With rodio
, Is there anyway to play sound from a Vec<u8>
or similar? I want to be able to read data from a zip file (I’m using the zip
crate) into memory and then play it back later. I’ve tried just about everything but I can’t figure it out.
I tried
let sound_data = self.sounds.clone();
let cursor = Cursor::new(sound_data.as_slice());
let source = Decoder::new(cursor).unwrap();
// Play the sound directly on the device
self.audio_output.1.play_raw(source.convert_samples());
where sound_data
is a Arc<Vec>. This complains that sound_data
does not live long enough, and that play_raw
requires the ‘static lifetime. I’ve also tried various similar configurations involving &[u8]
s, BufReaders
, etc but none of them work. I’m relatively new to Rust (have tried a few small projects before), and this is making me crazy.