12

This question has been asked and answered twice before on this site, but that code doesn't seem to work on modern phones at all. I'm working on an Android 4.2 and an Android 4.3 and neither seems to work.

I am playing an MP3 through a Media Player during the call, and it works fine, but both the song and the call are coming through the voice speaker. If I press "Speaker" they both continue playing through the loudspeaker. I need that effect, but without having to press it myself

    AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    audioManager.setMode(AudioManager.MODE_IN_CALL);
    audioManager.setSpeakerphoneOn(true);

     <uses-permission android:name="android.permission.RECORD_AUDIO" />
     <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>

This was suggested as a solution to both other questions on S.O, but it simply doesn't work. It should, the code is fine, but it simply does nothing to the audio at all.

Thoughts?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Viktor Zafirovski
  • 449
  • 1
  • 5
  • 15
  • Did you check this quote in developer site " You can play back the audio data only to the standard output device. Currently, that is the mobile device speaker or a Bluetooth headset. You cannot play sound files in the conversation audio during a call." ---- http://developer.android.com/guide/topics/media/mediaplayer.html – Vishnu Prabhu Nov 19 '15 at 05:05
  • Are you able to play the sound file, through mobile speaker or headphones if you are in a call?. – Vishnu Prabhu Nov 19 '15 at 05:07
  • Yes, I stated that above, it works absolutely fine. Embarrassingly enough, an hour after I posted this question I found a solution. I created a separate thread in a "while(true)" that repeatedly runs the above code. That way the speaker is on and the music is playing along with the call. – Viktor Zafirovski Nov 19 '15 at 06:41

3 Answers3

1

I solved it. I created a thread that constantly runs the above three lines of code in a "While (true)". Works great.

Viktor Zafirovski
  • 449
  • 1
  • 5
  • 15
0

use this code:

    AudioManager audioManager = (AudioManager) yourActivity.getSystemService(Context.AUDIO_SERVICE);
                    audioManager.setMode(AudioManager.MODE_IN_CALL);
                    audioManager.setSpeakerphoneOn(true);
0

This worked for me, in your InCallService call setAudioRoute like this:

setAudioRoute(ROUTE_SPEAKER);
aurhe
  • 61
  • 2