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
How about this then:
// Make sure that streams following the PHONE routing strategy aren't forced
// to play in the speaker.
Class audioSystemClass = Class.forName("android.media.AudioSystem");
Method setForceUse = audioSystemClass.getMethod("setForceUse",
int.class,
int.class);
// First 0 == FOR_COMMUNICATION, second 0 == FORCE_NONE.
setForceUse.invoke(null, 0, 0);
Then use STREAM_VOICE_CALL
for your MediaPlayer.
If the setForceUse
call succeeds and the audio from your MediaPlayer still plays in the loudspeaker, then I'd say something is messed up in the AudioPolicyManager implementation on the phone/tablet that you're testing this on.