From e0095c3aff264ca12faf11a9507518104080b9f2 Mon Sep 17 00:00:00 2001 From: Craig Martin Date: Wed, 12 Apr 2023 17:43:52 -0400 Subject: [PATCH] Make sure audioOutput is respected on first render --- .../exoplayer/ReactExoplayerView.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index f32d7e44..310a52df 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -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) {