From 723dfee067c05c643b035d7a6bf0fc1cfabe0e5d Mon Sep 17 00:00:00 2001 From: Michael Tintiuc Date: Sat, 1 Feb 2020 20:57:54 +0200 Subject: [PATCH 1/2] Fix audio focus --- .../java/com/brentvatne/exoplayer/ReactExoplayerView.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index 4802a5a435..c993eaa347 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -580,6 +580,10 @@ private DataSource.Factory buildDataSourceFactory(boolean useBandwidthMeter) { public void onAudioFocusChange(int focusChange) { switch (focusChange) { case AudioManager.AUDIOFOCUS_LOSS: + eventEmitter.audioFocusChanged(false); + audioManager.abandonAudioFocus(this); + break; + case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT: eventEmitter.audioFocusChanged(false); break; case AudioManager.AUDIOFOCUS_GAIN: From 1ab82f773d57efb9310e04faa8b94da8c1efbda8 Mon Sep 17 00:00:00 2001 From: Michael Tintiuc Date: Tue, 11 Feb 2020 11:00:31 +0200 Subject: [PATCH 2/2] Pause playback on focus loss --- .../main/java/com/brentvatne/exoplayer/ReactExoplayerView.java | 1 + 1 file changed, 1 insertion(+) diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index c993eaa347..eed33d16ef 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -581,6 +581,7 @@ public void onAudioFocusChange(int focusChange) { switch (focusChange) { case AudioManager.AUDIOFOCUS_LOSS: eventEmitter.audioFocusChanged(false); + pausePlayback(); audioManager.abandonAudioFocus(this); break; case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT: