List of usage examples for android.media MediaPlayer create
public static MediaPlayer create(Context context, int resid, AudioAttributes audioAttributes, int audioSessionId)
From source file:io.github.carlorodriguez.morningritual.MainActivity.java
private void notifyStepFinish() { if (vibrateWhenStepFinish()) { ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(500); }//w w w.jav a 2s . c o m if (soundWhenStepFinish()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { AudioAttributes audioAttributes = new AudioAttributes.Builder() .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .setUsage(AudioAttributes.USAGE_NOTIFICATION).build(); AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); MediaPlayer.create(this, R.raw.sound, audioAttributes, audioManager.generateAudioSessionId()) .start(); } else { try { playLegacyNotificationSound(); } catch (IOException e) { Toast.makeText(MainActivity.this, R.string.cannot_load_notification_sound, Toast.LENGTH_SHORT) .show(); } } } }