Skip to content

Re-resolve output device on each StreamStart#41

Merged
teancom merged 1 commit intomainfrom
fix/reresolve-device-on-stream-start
Apr 29, 2026
Merged

Re-resolve output device on each StreamStart#41
teancom merged 1 commit intomainfrom
fix/reresolve-device-on-stream-start

Conversation

@teancom
Copy link
Copy Markdown
Contributor

@teancom teancom commented Apr 29, 2026

The cpal::Device was captured once per WebSocket connection and reused for every CreatePlayer. On macOS with Bluetooth, sleep/reconnect cycles invalidate that handle (CoreAudio assigns a new AudioObjectID), so build_output_stream returned DeviceNotAvailable indefinitely until the WebSocket itself reconnected. The playback thread now takes the configured device id and calls resolve_output_device fresh on each CreatePlayer.

Mid-stream device loss is intentionally not auto-recovered — only the user's next play action triggers a re-resolve. Avoids surprise audio re-routing when e.g. AirPods come out mid-song.

The cpal::Device was captured once per WebSocket connection and reused
for every CreatePlayer. On macOS with Bluetooth, sleep/reconnect cycles
invalidate that handle (CoreAudio assigns a new AudioObjectID), so
build_output_stream returned DeviceNotAvailable indefinitely until the
WebSocket itself reconnected. The playback thread now takes the
configured device id and calls resolve_output_device fresh on each
CreatePlayer.

Mid-stream device loss is intentionally not auto-recovered — only the
user's next play action triggers a re-resolve. Avoids surprise audio
re-routing when e.g. AirPods come out mid-song.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@teancom teancom self-assigned this Apr 29, 2026
@teancom teancom added the bug Something isn't working label Apr 29, 2026
@teancom
Copy link
Copy Markdown
Contributor Author

teancom commented Apr 29, 2026

I've been testing this for ~3 days and it seems to be stable / does the right thing on my machine when going back and forth between built-in speaker and headphones.

@teancom teancom merged commit 1d0ce1b into main Apr 29, 2026
2 checks passed
@teancom teancom deleted the fix/reresolve-device-on-stream-start branch April 29, 2026 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant