【问题标题】:WebRTC Native Android Switch audio source?WebRTC Native Android Switch 音源?
【发布时间】:2020-05-14 18:14:42
【问题描述】:
我正在使用 webrtc native for android 并且在使用蓝牙时,webrtc lib 没有选择蓝牙耳机作为默认麦克风,所以如何切换麦克风的音频源,就像在 whatsapp 中一样,
目前我正在创建像这样的音频源,
AudioSource audioSource = peerConnectionFactory.createAudioSource(new MediaConstraints());
AudioTrack localAudioTrack = peerConnectionFactory.createAudioTrack("ARDAMSv1", audioSource);
【问题讨论】:
标签:
android
webrtc
native
【解决方案1】:
您不需要更改 webrtc audioTrack,只需更改 AudioManager 设置。使用蓝牙耳机:
private val audioManager: AudioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
if (!audioManager.isBluetoothScoOn) {
audioManager.startBluetoothSco()
}
audioManager.isBluetoothScoOn = true
切换回手机扬声器:
audioManager.isBluetoothScoOn = false
audioManager.stopBluetoothSco()
我不t properly remember, but if code above doesnt 工作,也像这样更改音频管理器模式:
audioManager.mode = AudioManager.MODE_IN_COMMUNICATION