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
i just wanted to add a complete example for Deepak Bala's Answer. It works when not using the MediaPlayer.create() method:
this.player = new MediaPlayer();
this.player.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
try {
this.player.setDataSource(getContext(), Uri.fromFile(new File(m.localFileUrl)));
this.player.prepare();
} catch (IllegalStateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}