Fixed Exoplayer doesn't work with mute=true #1696

This commit is contained in:
Andrew Chae 2019-08-01 11:33:28 -07:00
parent c29244bf89
commit 3012b81701

View File

@ -116,6 +116,7 @@ class ReactExoplayerView extends FrameLayout implements
private boolean isInBackground; private boolean isInBackground;
private boolean isPaused; private boolean isPaused;
private boolean isBuffering; private boolean isBuffering;
private boolean muted = false;
private float rate = 1f; private float rate = 1f;
private float audioVolume = 1f; private float audioVolume = 1f;
private int minLoadRetryCount = 3; private int minLoadRetryCount = 3;
@ -576,13 +577,17 @@ class ReactExoplayerView extends FrameLayout implements
if (player != null) { if (player != null) {
if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) { if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
// Lower the volume // Lower the volume
if (!muted) {
player.setVolume(audioVolume * 0.8f); player.setVolume(audioVolume * 0.8f);
}
} else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) { } else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
// Raise it back to normal // Raise it back to normal
if (!muted) {
player.setVolume(audioVolume * 1); player.setVolume(audioVolume * 1);
} }
} }
} }
}
// AudioBecomingNoisyListener implementation // AudioBecomingNoisyListener implementation
@ -912,6 +917,7 @@ class ReactExoplayerView extends FrameLayout implements
private void applyModifiers() { private void applyModifiers() {
setRepeatModifier(repeat); setRepeatModifier(repeat);
setMutedModifier(muted);
} }
public void setRepeatModifier(boolean repeat) { public void setRepeatModifier(boolean repeat) {
@ -1069,6 +1075,7 @@ class ReactExoplayerView extends FrameLayout implements
} }
public void setMutedModifier(boolean muted) { public void setMutedModifier(boolean muted) {
this.muted = muted;
audioVolume = muted ? 0.f : 1.f; audioVolume = muted ? 0.f : 1.f;
if (player != null) { if (player != null) {
player.setVolume(audioVolume); player.setVolume(audioVolume);