Commit b6bc06e
fix(audio): clear audioSwitch synchronously in AudioSwitchHandler.stop() (#967)
Audio output could get stuck on the earpiece (very low volume) after a
disconnect() + connect() on a reused Room on Android 12+
(CommDeviceAudioSwitch).
stop() nulled `audioSwitch` inside the posted teardown runnable while
tearing down handler/thread synchronously. Because the field was not
volatile and the write happened off the lock on the handler thread, a
fast subsequent start() could read a stale (already-stopped) switch and
skip re-creation via the `if (audioSwitch == null)` guard. With no new
switch created, activate() never re-ran, so the routing cleared by the
prior deactivate()'s clearCommunicationDevice() was never re-asserted and
playout stayed on the earpiece until the next connect.
Clear `audioSwitch` synchronously under the lock and mark it @volatile so
start() reliably observes the teardown and re-creates the switch. The
switch's stop() is still posted to its handler thread, since
AbstractAudioSwitch is not threadsafe.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 0c12e90 commit b6bc06e
2 files changed
Lines changed: 17 additions & 2 deletions
File tree
- .changeset
- livekit-android-sdk/src/main/java/io/livekit/android/audio
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Lines changed: 12 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
202 | 205 | | |
203 | 206 | | |
204 | 207 | | |
| |||
261 | 264 | | |
262 | 265 | | |
263 | 266 | | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
264 | 275 | | |
265 | 276 | | |
266 | | - | |
267 | | - | |
| 277 | + | |
268 | 278 | | |
269 | 279 | | |
270 | 280 | | |
| |||
0 commit comments