I found out how this can be done. Notice that MediaPlayer and AudioManger are in the same mode. I tried this on Nexus 5 (4.4.2)
final AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
audioManager.setSpeakerphoneOn(true);
MediaPlayer mp = null;
mp = MediaPlayer.create(this, R.raw.bad);
mp.setAudioStreamType(AudioManager.MODE_IN_COMMUNICATION);
mp.start();