How to correctly set MediaPlayer audio stream type

Okay, I found the solution after a bit more testing and it looks like this, in case anyone else runs into the same problem I was having. The MODIFY_AUDIO_SETTINGS permission is needed in the Manifest for this to work.

AudioManager am=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
am.setMode(AudioManager.MODE_NORMAL);
MediaPlayer mp=new MediaPlayer();
Uri ringtoneUri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
try
{
    mp.setDataSource(getApplicationContext(), ringtoneUri);
    mp.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
    mp.prepare();
    mp.start();
}
catch(Exception e)
{
    //exception caught in the end zone
}

Leave a Comment