How to control audio output levels with PJSUA2 for Android

I have an Android project that uses PJSUA2 for VoIP communication and everything else works just fine. However, I'm getting stuck, with an issue where I can't get the volume controls to work in the Activity where my active call is displayed. I have tried doing it in the recommended way -

audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
setVolumeControlStream(AudioManager.STREAM_MUSIC);

      

It doesn't do anything. I need to know if using OnKey Listeners is a possible alternative to manually increasing and decreasing the volume, or if I am missing something entirely that will allow me to do this in my preferred way.

+1


source to share


2 answers


When the call is in the connected state, you need to set the audio mode to MODE_IN_COMMUNICATION

and set to MODE_NORMAL

when disconnected.



// set mode to 3 to indicate MODE_IN_COMMUNICATION mode
((AudioManager) getSystemService(Context.AUDIO_SERVICE)).setMode(3);
// set audio mode to normal again on call disconnection
((AudioManager) getSystemService(Context.AUDIO_SERVICE)).setMode(AudioManager.MODE_NORMAL);

      

+1


source


So I finally figured out how to do it intelligently with PJSUA to implement my own keypress handler and then change the Rx Audio Levels accordingly. Hope this helps someone who is stuck as bad as me.



0


source







All Articles