I would like to play a mp3 audio file with the same speaker and volume when an user receive a phone call.
I am using the following code
int result = audioManager.requestAudioFocus(afChangeListener,
AudioManager.MODE_IN_CALL,
AudioManager.AUDIOFOCUS_GAIN);
audioManager.setSpeakerphoneOn(true);
with the
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
in the manifest
but it does not work. the volume is very high.
Any idea?
What that call to
setSpeakerPhoneOn(most likely) will do is to route both the music and the voice call to the loudspeaker, in which case they might be mixed together and the music may be downsampled to the voice call sample rate (8 or 16 kHz).One thing you could try is what I proposed in how to turn speaker on/off programatically in android 4.0
This could let you let you route only the music to the loudspeaker while voice call audio is routed to the earpiece. It’s not guaranteed to work on all devices though.