Issue
I'm developing a voice call app using peer.js and WebView. My intention is to play the remote stream through the earpiece or Bluetooth headphones(If connected). And there should be an option to switch to the loudspeaker as well. I tried the following code but the audio still comes from the loudspeaker.
private fun setupAudio() {
val am = getSystemService(AUDIO_SERVICE) as AudioManager
am.mode = AudioManager.MODE_IN_CALL
am.isSpeakerphoneOn = false
}
Is there any better way to do this? Or can I change the AudioStreamType of WebView(Like as in MediaPlayer)?
Solution
I got it working, the trick is to call the am.isSpeakerphoneOn = false
after receiving the stream.
Answered By - Sujith Manjavana