diff --git a/android/src/main/java/com/brentvatne/exoplayer/AudioOutput.java b/android/src/main/java/com/brentvatne/exoplayer/AudioOutput.java index dc2354ae..0745536b 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/AudioOutput.java +++ b/android/src/main/java/com/brentvatne/exoplayer/AudioOutput.java @@ -24,6 +24,10 @@ public enum AudioOutput { return SPEAKER; } + public int getStreamType() { + return streamType; + } + @Override public String toString() { return getClass().getSimpleName() + "(" + this.mName + ", " + streamType + ")"; diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index e908ca0a..8ef2afca 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -1825,17 +1825,19 @@ class ReactExoplayerView extends FrameLayout implements private void changeAudioOutput(AudioOutput output) { if (player != null) { - int usage = Util.getAudioUsageForStreamType(audioOutput.streamType); - int contentType = Util.getAudioContentTypeForStreamType(audioOutput.streamType); + int streamType = output.getStreamType(); + int usage = Util.getAudioUsageForStreamType(streamType); + int contentType = Util.getAudioContentTypeForStreamType(streamType); AudioAttributes audioAttributes = new AudioAttributes.Builder().setUsage(usage) .setContentType(contentType) .build(); player.setAudioAttributes(audioAttributes, false); AudioManager audioManager = (AudioManager) themedReactContext.getSystemService(Context.AUDIO_SERVICE); + boolean isSpeakerOutput = output == AudioOutput.SPEAKER; audioManager.setMode( - audioOutput == AudioOutput.SPEAKER ? AudioManager.MODE_NORMAL + isSpeakerOutput ? AudioManager.MODE_NORMAL : AudioManager.MODE_IN_COMMUNICATION); - audioManager.setSpeakerphoneOn(audioOutput == AudioOutput.SPEAKER); + audioManager.setSpeakerphoneOn(isSpeakerOutput); } } diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java index 606f1504..5b476dd5 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java @@ -5,6 +5,7 @@ import android.content.Context; import android.net.Uri; import android.text.TextUtils; +import com.brentvatne.exoplayer.AudioOutput; import com.facebook.react.bridge.Dynamic; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; @@ -280,7 +281,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager