Skip to content

Commit

Permalink
fix(android): use UI thread to pause when lost audio focus (#3916)
Browse files Browse the repository at this point in the history
  • Loading branch information
freeboub authored Jun 20, 2024
1 parent 264b57a commit 856b1dd
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1172,12 +1172,16 @@ private OnAudioFocusChangedListener(ReactExoplayerView view, ThemedReactContext

@Override
public void onAudioFocusChange(int focusChange) {
Activity activity = themedReactContext.getCurrentActivity();

switch (focusChange) {
case AudioManager.AUDIOFOCUS_LOSS:
view.hasAudioFocus = false;
view.eventEmitter.audioFocusChanged(false);
// FIXME this pause can cause issue if content doesn't have pause capability (can happen on live channel)
view.pausePlayback();
if (activity != null) {
activity.runOnUiThread(view::pausePlayback);
}
view.audioManager.abandonAudioFocus(this);
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
Expand All @@ -1191,7 +1195,6 @@ public void onAudioFocusChange(int focusChange) {
break;
}

Activity activity = themedReactContext.getCurrentActivity();
if (view.player != null && activity != null) {
if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
// Lower the volume
Expand Down

0 comments on commit 856b1dd

Please sign in to comment.