rustrodio

How can I know when a Rodio source or sink is done?


I'm trying to play some sounds with rodio.

I am creating a Source and putting it into a Sink, but how can I know when one or the other has stopped playing? For example, I want to move to the next song after the first.

let device = rodio::default_output_device().unwrap();
let sink = Sink::new(&device);
let file = File::open(path).unwrap();
let source = rodio::Decoder::new(BufReader::new(file)).unwrap();
sink.append(source);

I have found nothing in the rodio docs about a callback or something similar. There is a Done struct, but it's not clear to me how to use it, or even if is the thing I'm looking for.


Solution

  • I think you're looking for the Sink::done which returns true if there are no more samples within the sink to play.