Merge pull request #3233 from mysport12/master
Fix: AudioOutput on Android
This commit is contained in:
commit
0fac437dbd
@ -24,6 +24,10 @@ public enum AudioOutput {
|
|||||||
return SPEAKER;
|
return SPEAKER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getStreamType() {
|
||||||
|
return streamType;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getClass().getSimpleName() + "(" + this.mName + ", " + streamType + ")";
|
return getClass().getSimpleName() + "(" + this.mName + ", " + streamType + ")";
|
||||||
|
@ -1825,17 +1825,19 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
|
|
||||||
private void changeAudioOutput(AudioOutput output) {
|
private void changeAudioOutput(AudioOutput output) {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
int usage = Util.getAudioUsageForStreamType(audioOutput.streamType);
|
int streamType = output.getStreamType();
|
||||||
int contentType = Util.getAudioContentTypeForStreamType(audioOutput.streamType);
|
int usage = Util.getAudioUsageForStreamType(streamType);
|
||||||
|
int contentType = Util.getAudioContentTypeForStreamType(streamType);
|
||||||
AudioAttributes audioAttributes = new AudioAttributes.Builder().setUsage(usage)
|
AudioAttributes audioAttributes = new AudioAttributes.Builder().setUsage(usage)
|
||||||
.setContentType(contentType)
|
.setContentType(contentType)
|
||||||
.build();
|
.build();
|
||||||
player.setAudioAttributes(audioAttributes, false);
|
player.setAudioAttributes(audioAttributes, false);
|
||||||
AudioManager audioManager = (AudioManager) themedReactContext.getSystemService(Context.AUDIO_SERVICE);
|
AudioManager audioManager = (AudioManager) themedReactContext.getSystemService(Context.AUDIO_SERVICE);
|
||||||
|
boolean isSpeakerOutput = output == AudioOutput.SPEAKER;
|
||||||
audioManager.setMode(
|
audioManager.setMode(
|
||||||
audioOutput == AudioOutput.SPEAKER ? AudioManager.MODE_NORMAL
|
isSpeakerOutput ? AudioManager.MODE_NORMAL
|
||||||
: AudioManager.MODE_IN_COMMUNICATION);
|
: 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.net.Uri;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.brentvatne.exoplayer.AudioOutput;
|
||||||
import com.facebook.react.bridge.Dynamic;
|
import com.facebook.react.bridge.Dynamic;
|
||||||
import com.facebook.react.bridge.ReadableArray;
|
import com.facebook.react.bridge.ReadableArray;
|
||||||
import com.facebook.react.bridge.ReadableMap;
|
import com.facebook.react.bridge.ReadableMap;
|
||||||
@ -280,7 +281,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
|||||||
|
|
||||||
@ReactProp(name = PROP_AUDIO_OUTPUT)
|
@ReactProp(name = PROP_AUDIO_OUTPUT)
|
||||||
public void setAudioOutput(final ReactExoplayerView videoView, final String audioOutput) {
|
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)
|
@ReactProp(name = PROP_VOLUME, defaultFloat = 1.0f)
|
||||||
|
Loading…
Reference in New Issue
Block a user