mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +00:00
feat(audio): auto-switch to new audio output device at runtime
Adds a background device-watcher that polls the OS default output device every 3 s via CPAL. When the device changes (Bluetooth headphones connecting, USB DAC plugging in, etc.) the stream is reopened on the new device, the old Sink is dropped (it was bound to the now-closed OutputStream), and audio:device-changed is emitted to the frontend. Frontend handler (TauriEventBridge): if playing, restarts the current track from the saved position; if paused, clears the warm-pause flag so the next resume uses the cold path (audio_play + seek) which creates a new Sink on the new device. Fixes #143 (audio through speakers after connecting Bluetooth headphones). Also covers the intermittently reported single-channel output after long idle, which can be caused by the OS reconfiguring the audio device in the background. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1386,6 +1386,13 @@ pub fn run() {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Audio device-change watcher ───────────────────────────────
|
||||
{
|
||||
use tauri::Manager;
|
||||
let engine = app.state::<audio::AudioEngine>();
|
||||
audio::start_device_watcher(&engine, app.handle().clone());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.on_window_event(|window, event| {
|
||||
|
||||
Reference in New Issue
Block a user