Search code examples
androidwebviewwebrtcpeerjs

android webRTC voice call


I want to develop a voice call app for android. As the native android webRTC project is not maintained and lacks good documentation, I ended up using the peerjs library with webView. And it's working. But the problem is that webView doesn't provide any function to change the audio output stream. Audio is always played on the loudspeaker. I want it to be played on the earpiece. How can I achieve this?


Solution

  • I figured it out myself

    //call only after the playback starts
    fun setupAudio() {
            val am = getSystemService(AUDIO_SERVICE) as AudioManager
            am.mode = AudioManager.MODE_IN_COMMUNICATION
            //am.stopBluetoothSco()
            am.isSpeakerphoneOn = false
        }