From 3012b81701bbe760eab3e7074ef3252304007549 Mon Sep 17 00:00:00 2001 From: Andrew Chae Date: Thu, 1 Aug 2019 11:33:28 -0700 Subject: [PATCH] Fixed Exoplayer doesn't work with mute=true #1696 --- .../com/brentvatne/exoplayer/ReactExoplayerView.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 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 1edb8c7a..cd9b4c4d 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -116,6 +116,7 @@ class ReactExoplayerView extends FrameLayout implements private boolean isInBackground; private boolean isPaused; private boolean isBuffering; + private boolean muted = false; private float rate = 1f; private float audioVolume = 1f; private int minLoadRetryCount = 3; @@ -576,10 +577,14 @@ class ReactExoplayerView extends FrameLayout implements if (player != null) { if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) { // Lower the volume - player.setVolume(audioVolume * 0.8f); + if (!muted) { + player.setVolume(audioVolume * 0.8f); + } } else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) { // Raise it back to normal - player.setVolume(audioVolume * 1); + if (!muted) { + player.setVolume(audioVolume * 1); + } } } } @@ -912,6 +917,7 @@ class ReactExoplayerView extends FrameLayout implements private void applyModifiers() { setRepeatModifier(repeat); + setMutedModifier(muted); } public void setRepeatModifier(boolean repeat) { @@ -1069,6 +1075,7 @@ class ReactExoplayerView extends FrameLayout implements } public void setMutedModifier(boolean muted) { + this.muted = muted; audioVolume = muted ? 0.f : 1.f; if (player != null) { player.setVolume(audioVolume);