Skip to content

Commit

Permalink
Merge pull request #1327 from ddudek/fix/android_volume_focus_change
Browse files Browse the repository at this point in the history
Fix: volume should not change on onAudioFocusChange event
  • Loading branch information
cobarx authored Nov 19, 2018
2 parents 30c30ec + 341260f commit 1207d45
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* Switch useTextureView to default to `true` [#1286](https://github.com/react-native-community/react-native-video/pull/1286)
* Re-add fullscreenAutorotate prop [#1303](https://github.com/react-native-community/react-native-video/pull/1303)
* Make seek throw a useful error for NaN values [#1283](https://github.com/react-native-community/react-native-video/pull/1283)
* 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -454,10 +455,10 @@ public void onAudioFocusChange(int focusChange) {
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);
}
}
}
Expand Down Expand Up @@ -875,15 +876,17 @@ public void setPausedModifier(boolean paused) {
}

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);
}
}

Expand Down

0 comments on commit 1207d45

Please sign in to comment.