Make sure audioOutput is respected on first render

This commit is contained in:
Craig Martin 2023-04-12 17:43:52 -04:00
parent daabb91475
commit e0095c3aff

View File

@ -694,6 +694,7 @@ class ReactExoplayerView extends FrameLayout implements
PlaybackParameters params = new PlaybackParameters(rate, 1f);
player.setPlaybackParameters(params);
changeAudioOutput(this.audioOutput);
}
private DrmSessionManager initializePlayerDrm(ReactExoplayerView self) {
@ -1857,21 +1858,29 @@ class ReactExoplayerView extends FrameLayout implements
}
}
public void setAudioOutput(AudioOutput output) {
if (audioOutput != output && player != null) {
this.audioOutput = output;
private void changeAudioOutput(AudioOutput output) {
if (player != null) {
int usage = Util.getAudioUsageForStreamType(audioOutput.streamType);
int contentType = Util.getAudioContentTypeForStreamType(audioOutput.streamType);
AudioAttributes audioAttributes = new AudioAttributes.Builder().setUsage(usage).setContentType(contentType)
AudioAttributes audioAttributes = new AudioAttributes.Builder().setUsage(usage)
.setContentType(contentType)
.build();
player.setAudioAttributes(audioAttributes, false);
AudioManager audioManager = (AudioManager) themedReactContext.getSystemService(Context.AUDIO_SERVICE);
audioManager.setMode(
audioOutput == AudioOutput.SPEAKER ? AudioManager.MODE_NORMAL : AudioManager.MODE_IN_COMMUNICATION);
audioOutput == AudioOutput.SPEAKER ? AudioManager.MODE_NORMAL
: AudioManager.MODE_IN_COMMUNICATION);
audioManager.setSpeakerphoneOn(audioOutput == AudioOutput.SPEAKER);
}
}
public void setAudioOutput(AudioOutput output) {
if (audioOutput != output) {
this.audioOutput = output;
changeAudioOutput(output);
}
}
public void setVolumeModifier(float volume) {
audioVolume = volume;
if (player != null) {