Skip to content

Commit

Permalink
Merge pull request TheWidlarzGroup#1699 from andrewchae/mute
Browse files Browse the repository at this point in the history
Fixed Exoplayer doesn't work with mute=true TheWidlarzGroup#1696

(rebased from commit b954a4f)
  • Loading branch information
CHaNGeTe authored and Beau Ner committed Oct 10, 2019
1 parent 052ef65 commit 1b0854a
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -592,10 +593,14 @@ public void onAudioFocusChange(int focusChange) {
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);
}
}
}
}
Expand Down Expand Up @@ -948,6 +953,7 @@ public void setResizeModeModifier(@ResizeMode.Mode int resizeMode) {

private void applyModifiers() {
setRepeatModifier(repeat);
setMutedModifier(muted);
}

public void setRepeatModifier(boolean repeat) {
Expand Down Expand Up @@ -1105,6 +1111,7 @@ public void setPausedModifier(boolean paused) {
}

public void setMutedModifier(boolean muted) {
this.muted = muted;
audioVolume = muted ? 0.f : 1.f;
if (player != null) {
player.setVolume(audioVolume);
Expand Down

0 comments on commit 1b0854a

Please sign in to comment.