WebRTC Native Android Switch audio source?

Viewed 1033

I am using webrtc native for android and while using bluetooth, the webrtc lib doesn't select the bluetooth headset as default mic, so how to switch audio source that is microphone, like in the whatsapp, currently i am creating audio source like as,

        AudioSource audioSource = peerConnectionFactory.createAudioSource(new MediaConstraints());

        AudioTrack localAudioTrack = peerConnectionFactory.createAudioTrack("ARDAMSv1", audioSource); 
1 Answers

You don`t need to change webrtc audioTrack, only AudioManager settings. To use bluetooth headset:

private val audioManager: AudioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager    
if (!audioManager.isBluetoothScoOn) {
                        audioManager.startBluetoothSco()
                    }
audioManager.isBluetoothScoOn = true

To switch back to phone speaker:

audioManager.isBluetoothScoOn = false
audioManager.stopBluetoothSco()

And I dont properly remember, but if code above doesnt work, change also audiomanager mode like this:

audioManager.mode = AudioManager.MODE_IN_COMMUNICATION
Related