RustAudio / rodio

Rust audio playback library
Apache License 2.0
1.74k stars 228 forks source link

Skipping Samples from Decoder #165

Open Capital-EX opened 6 years ago

Capital-EX commented 6 years ago

Is there any way to skip over audio samples using radio? I tried to seek the BufReader forward but that results in an UnrecognizedFormat error. The only way I've found that works requires reading the full file into memory:

let sample_rate = decoder.sample_rate();
let channels = decoder.channels();
let source = decoder.skip((sample_rate * 10) as usize).collect::<Vec<i16>>(); // decode the full song
sink.append(rodio::buffer::SamplesBuffer::new(channels, sample_rate, source));
AntonHermann commented 6 years ago

Shouldn't be that difficult to implement, as far as I can tell. Isn't that just basically the thing skip() does for iterators, maybe with a little bit extra logic for the total duration (the last of the Source trait functions)?