1

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.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Carlo
  • 2,103
  • 21
  • 29
  • `Sink` has [`Sink::empty`](https://docs.rs/rodio/0.11.0/rodio/struct.Sink.html#method.empty). [`Sink::sleep_until_end`](https://docs.rs/rodio/0.11.0/rodio/struct.Sink.html#method.sleep_until_end) might also work depending on your usecase. – SCappella Mar 24 '20 at 18:18
  • sleep_until_end blocks the thread, so does not seem a good idea. Sink::empty means I have to poll that variable until it's true ? :-| – Carlo Mar 25 '20 at 15:28

1 Answers1

1

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

JKnight
  • 1,996
  • 2
  • 14
  • 23