From 5c7da30ddb408220b39251a6b0435e208ff963b6 Mon Sep 17 00:00:00 2001 From: Daniel Dudek Date: Wed, 14 Nov 2018 12:33:28 +0100 Subject: [PATCH 1/2] Fixed volume change when audio focus change --- .../com/brentvatne/exoplayer/ReactExoplayerView.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 3d141f3c..7d69368e 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -109,6 +109,7 @@ class ReactExoplayerView extends FrameLayout implements private boolean isPaused; private boolean isBuffering; private float rate = 1f; + private float audioVolume = 1f; private int minBufferMs = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS; private int maxBufferMs = DefaultLoadControl.DEFAULT_MAX_BUFFER_MS; @@ -454,10 +455,10 @@ class ReactExoplayerView extends FrameLayout implements if (player != null) { if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) { // Lower the volume - player.setVolume(0.8f); + player.setVolume(audioVolume * 0.8f); } else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) { // Raise it back to normal - player.setVolume(1); + player.setVolume(audioVolume * 1); } } } @@ -875,15 +876,17 @@ class ReactExoplayerView extends FrameLayout implements } public void setMutedModifier(boolean muted) { + audioVolume = muted ? 0.f : 1.f; if (player != null) { - player.setVolume(muted ? 0 : 1); + player.setVolume(audioVolume); } } public void setVolumeModifier(float volume) { + audioVolume = volume; if (player != null) { - player.setVolume(volume); + player.setVolume(audioVolume); } } From 13cdac8611781e80805ddc4fbadc66bc74022c24 Mon Sep 17 00:00:00 2001 From: Daniel Dudek Date: Wed, 14 Nov 2018 12:47:18 +0100 Subject: [PATCH 2/2] Updated CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e84036a..297a807f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * Add fullscreenOrientation option for iOS [#1215](https://github.com/react-native-community/react-native-video/pull/1215) * Update to ExoPlayer 2.9.0 [#1285](https://github.com/react-native-community/react-native-video/pull/1285) * Switch useTextureView to default to `true` [#1286](https://github.com/react-native-community/react-native-video/pull/1286) +* Fix: volume should not change on onAudioFocusChange event [#1327](https://github.com/react-native-community/react-native-video/pull/1327) ### Version 3.2.0 * Basic fullscreen support for Android MediaPlayer [#1138](https://github.com/react-native-community/react-native-video/pull/1138)