-->

How do I manage the audio output levels with PJSUA

2019-07-23 15:03发布

问题:

I have an Android project that uses PJSUA2 for VoIP communication and everything else works just fine. I am stymied however, with a problem where I cannot get the Volume controls to work in the Activity where my active call is shown. I have tried doing it the recommended way -

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

This doesn't do anything. I need to know if using OnKey Listeners is a feasible alternative to manually increase and decrease the volume or if I am missing something completely which will let me do it the preferred way.

回答1:

When call is in connected state you have to set audio mode to MODE_IN_COMMUNICATION and set to MODE_NORMAL on disconnect.

// 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);


回答2:

So I finally figured out the way to do this reasonably with PJSUA was to implement my own keypress handler and then vary the Rx Audio Levels accordingly. Hope this helps someone who was stuck as bad as I was.