Skip to content

Re-resolve output device on each StreamStart#40

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

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

Conversation

@teancom
Copy link
Copy Markdown
Contributor

@teancom teancom commented Apr 27, 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.

This is the PR I mentioned when merging #39

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 27, 2026
@teancom teancom added the bug Something isn't working label Apr 27, 2026
@teancom
Copy link
Copy Markdown
Contributor Author

teancom commented Apr 28, 2026

Tested for a couple of days, seems to be working well so far. 🤞

@teancom teancom merged commit c688c84 into main Apr 28, 2026
1 check passed
@teancom teancom deleted the fix/reresolve-device-on-stream-start branch April 28, 2026 19:55
@teancom teancom restored the fix/reresolve-device-on-stream-start branch April 29, 2026 19:10
@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