2

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.

hanut
  • 505
  • 4
  • 24
  • I'm also having the same problem @Hanut. When running my app, some mobiles giving good audio level , but in some mobiles its not hearable and very low audio level. But the volume level in phone is always high.How to solve this problem? did you found this ? please help me – Nandhakumar Kittusamy May 14 '17 at 10:34

3 Answers3

2

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);
  • 1
    It worked for me. All I did is set audioManager?.mode = AudioManager.MODE_IN_COMMUNICATION when call started and set audioManager?.mode = AudioManager.MODE_NORMAL when call ended. – Aanal Shah Sep 17 '19 at 13:30
0

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.

hanut
  • 505
  • 4
  • 24
0

Pjsip by default uses the voice communication / phone stream for playing audio. To control the volume with the system volume control, you should adjust the call audio volume, not the media/music volume:

setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);

If you would rather that the audio is actually played back as a media/music type of stream and be controlled by that volume slider, see my suggestion for how to do that here

ade.se
  • 1,644
  • 1
  • 11
  • 11