0

I got an Android application which uses Linphone for VOIP calls.

When I receive a call, I'm starting a ringtone of my own (a raw mp3 file) like this:

final AudioManager audioManager = (AudioManager)ctx.getSystemService(Context.AUDIO_SERVICE);
final float maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
audioManager.setStreamVolume(AudioManager.STREAM_RING, (int)maxVolume , 0);
soundPool.play(id, maxVolume , maxVolume , 1, 0, 1.0f);

The sound I want is playing but with a low volume. The call itself is accepted automatically, without the need of permission from the receiving end.

If I receive the call and end the call before the sound finished, the sound will continue (this is ok) but the volume will suddenly be at a maximum like I wanted in the first place. This means, the device might be entering a call state in which the volume of the soundpool is automatically being decreased, and when the call ends, the sound can have the maximum value.

How can I set the volume to maximum even during a call?

CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
  • Hi Yonatan, what is your exact requirement? Do you want to play a sound while a call is going on? And why you want to play the sound while call is going on? What you want to achieve by doing this? – Chandrakanth Feb 03 '17 at 05:38
  • The call is automatically accepted so I need to play a sound to let the user know there's a call in progress. So I can play the sound but can't seem to put it on max volume as long as the call is in progress – CodeMonkey Feb 04 '17 at 13:43

1 Answers1

0

Since the volume is being automatically reduced, I had to try and accepting the call only after playing the sound. Since SoundPool does not support event handling when a sound finishes playing, I have switched to using a MediaPlayer which does support it, so I'm playing the ringing sound and then accepting the call after that.

CodeMonkey
  • 11,196
  • 30
  • 112
  • 203