Fix: AudioOutput on Android
This commit is contained in:
parent
eaa0b947d4
commit
0678a2ccf1
@ -24,6 +24,10 @@ public enum AudioOutput {
|
||||
return SPEAKER;
|
||||
}
|
||||
|
||||
public int getStreamType() {
|
||||
return streamType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + "(" + this.mName + ", " + streamType + ")";
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<ReactExoplayerVi
|
||||
|
||||
@ReactProp(name = PROP_AUDIO_OUTPUT)
|
||||
public void setAudioOutput(final ReactExoplayerView videoView, final String audioOutput) {
|
||||
videoView.setAudioOutput(ReactExoplayerView.AudioOutput.get(audioOutput));
|
||||
videoView.setAudioOutput(AudioOutput.get(audioOutput));
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_VOLUME, defaultFloat = 1.0f)
|
||||
|
Loading…
Reference in New Issue
Block a user