Example usage for android.media AudioManager generateAudioSessionId

List of usage examples for android.media AudioManager generateAudioSessionId

Introduction

In this page you can find the example usage for android.media AudioManager generateAudioSessionId.

Prototype

public int generateAudioSessionId() 

Source Link

Document

Return a new audio session identifier not associated with any player or effect.

Usage

From source file:io.github.carlorodriguez.morningritual.MainActivity.java

private void notifyStepFinish() {
    if (vibrateWhenStepFinish()) {
        ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(500);
    }/* w  w  w  .  ja  v  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();
            }
        }
    }
}