#50072·expo

[expo-audio] Android drops audio focus on a transient rebuffer and never re-requests it, so playback talks over phone calls

Author: dylankolsonCreated Sep 12, 2026Updated Sep 29, 2026
LabelsAndroid📦 expo-audioneeds reviewcontributor: externalsdk-57severity: medium

Summary

AudioModule.kt releases audio focus on any transition to not-playing, including the transient one ExoPlayer emits when a buffer empties mid-stream. Focus is only ever requested from the play Function, and a self-healing rebuffer never re-enters it — so after the first rebuffer the player keeps playing with no audio focus and no registered OnAudioFocusChangeListener, for the rest of the session.

https://github.com/expo/expo/blob/main/packages/expo-audio/android/src/main/java/expo/modules/audio/AudioModule.kt

kotlin
player.onPlaybackStateChange = { isPlaying ->
  if (!isPlaying && shouldReleaseFocus()) {
    releaseAudioFocus()
  }
}

onPlaybackStateChange is invoked from BaseAudioPlayer's Player.Listener.onIsPlayingChanged, which ExoPlayer fires on both edges of a rebuffer. shouldReleaseFocus() reads raw isPlaying across the registry, so during the buffering window nothing is playing and focus is released.

Why it is user-visible

Audio focus is what makes playback yield to an incoming call, a navigation prompt, or another media app. Once it has been dropped this way, the app talks straight over all of them — which is the one thing audio focus exists to prevent. For a long-running stream (a scanner, a radio app, a podcast on a flaky connection) a rebuffer is routine, so this is reached quickly and then persists.

Repro

  1. Start playback of a network stream.
  2. Force a brief rebuffer — airplane mode on for ~8 s, then off. Let the audio recover on its own. (If the app shows a full reconnect instead, the gap was too long: a reconnect re-enters play() and re-requests focus, masking the bug. Use a shorter gap.)
  3. Have someone call the phone.

Expected: playback pauses (or ducks) for the ring and the call. Actual: playback continues over the ringtone and the entire call.

Fix

Treat STATE_BUFFERING as transient and don't release on it:

kotlin
player.onPlaybackStateChange = { isPlaying ->
  val transient = player.ref.playbackState == Player.STATE_BUFFERING
  if (!isPlaying && !transient && shouldReleaseFocus()) {
    releaseAudioFocus()
  }
}

STATE_ENDED is deliberately still treated as a real stop.

Related, same area

The notification / lock-screen Play button never requests focus at all. media3 routes COMMAND_PLAY_PAUSE through MetadataInjectingPlayer → ForwardingPlayer → ExoPlayer directly, bypassing the play Function where the focus request lives — so the same control behaves differently in-app and from the notification. The tidier fix for both is probably to let ExoPlayer own focus via setAudioAttributes(attrs, handleAudioFocus = true) and drop the manual bookkeeping, but that is a larger change and running both would double-request, so I kept it out of the patch above.

Environment

  • [email protected], Expo SDK 57, react-native 0.86.2, bare workflow
  • Android 16 emulator (API 36), targetSdk/compileSdk 36
  • Verified with adb shell dumpsys audio before/after a rebuffer

Happy to open a PR if the approach looks right.