I\'d like to play audio from a file into the phone\'s earpiece (or headset of that is connected) using the android MediaPlayer
. I tried using the MODE_IN_CALL h
It turns out the right way to do this is through the following code.
Play through the ear piece
mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
Play through the speaker phone
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
That is it. Any other solution (Including the one posted here -> Android - Getting audio to play through earpiece) does not work consistently across devices. In fact using MODE_IN_CALL ensures that your audio will never play on certain devices.
Note: You will need to re-prepare the media player to change streams.