RustAudio / rodio

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

Sink stops playing sound when audio output device is disconnected and reconnected. #545

Closed sloganking closed 6 months ago

sloganking commented 7 months ago

When my audio output device that I think is using is unplugged, my terminal prints the output.:

an error occurred on output stream: The requested device is no longer available. For example, it has been unplugged. 

I'm not sure where this output is being printed from, presumably inside one of the Rodeo functions. I'm unwrapping on most of the exposed lib functions, so I don't know if this is something I can catch.

Is there a way to catch when a sync has gone bad, so that I can create a fresh working one?

dvdsk commented 6 months ago

Part of the error comes from cpal (which runs into an issue due to the unplug): https://github.com/est31/cpal/blob/7776c6634a8e21e2a585358545141fe091c38320/src/error.rs#L154

The way we interact with this error from Rodio is by passing in a handler (the error_callback): https://github.com/RustAudio/rodio/blob/616ee267563555bf0edb803e7073dfbb27c6de9e/src/stream.rs#L211

Right that callback just prints the error. Whether to stop the stream or continue is cpal's choice. It does not seem to be something we can catch.

Feel free to re-open if you have any questions.