Example usage for android.media AudioAttributes CONTENT_TYPE_SONIFICATION

List of usage examples for android.media AudioAttributes CONTENT_TYPE_SONIFICATION

Introduction

In this page you can find the example usage for android.media AudioAttributes CONTENT_TYPE_SONIFICATION.

Prototype

int CONTENT_TYPE_SONIFICATION

To view the source code for android.media AudioAttributes CONTENT_TYPE_SONIFICATION.

Click Source Link

Document

Content type value to use when the content type is a sound used to accompany a user action, such as a beep or sound effect expressing a key click, or event, such as the type of a sound for a bonus being received in a game.

Usage

From source file:MainActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void createSoundPoolNew() {
    AudioAttributes audioAttributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA)
            .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build();
    mSoundPool = new SoundPool.Builder().setAudioAttributes(audioAttributes).setMaxStreams(2).build();
}

From source file:com.kentli.cycletrack.RecordingService.java

@Override
public void onCreate() {
    super.onCreate();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        AudioAttributes attributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_GAME)
                .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build();

        soundpool = new SoundPool.Builder().setAudioAttributes(attributes).build();
    } else {//from   w  ww. j  a v  a2s  .  c o m
        soundpool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
    }
    soundpool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
        @Override
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
            soundPool.play(sampleId, 1.0f, 1.0f, 0, 0, 1.0f);
        }
    });
    bikebell = soundpool.load(this.getBaseContext(), R.raw.bikebell, 1);
}

From source file:ua.com.spasetv.testintuitions.FragExerciseOne.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected void createNewSoundPool() {
    AudioAttributes attributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_GAME)
            .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build();
    soundPool = new SoundPool.Builder().setAudioAttributes(attributes).build();
}

From source file:com.stillnojetpacks.huffr.activities.MainActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void initializeSoundPool() {
    if (soundPool != null) {
        soundPool.release();/*from ww  w .  j  ava  2  s . c  o  m*/
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        AudioAttributes audioAttributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_GAME)
                .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build();

        soundPool = new SoundPool.Builder().setMaxStreams(PREF_SOUNDPOOL_MAX_STREAMS)
                .setAudioAttributes(audioAttributes).build();
    } else {
        buildBeforeAPI21();
    }
    soundPool.setOnLoadCompleteListener(this);
}

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

private void notifyStepFinish() {
    if (vibrateWhenStepFinish()) {
        ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(500);
    }//from w ww.jav  a 2 s  .  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();
            }
        }
    }
}

From source file:org.wso2.iot.agent.AlertActivity.java

/**
 * This method is used to start ringing the phone.
 *//*from ww  w .ja v  a2s  .c  o  m*/
@TargetApi(21)
private void startRing() {
    if (audio != null) {
        ringerMode = audio.getRingerMode();
        ringerVolume = audio.getStreamVolume(AudioManager.STREAM_RING);
        audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        audio.setStreamVolume(AudioManager.STREAM_RING, audio.getStreamMaxVolume(AudioManager.STREAM_RING),
                AudioManager.FLAG_PLAY_SOUND);

        defaultRingtoneUri = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE);

        if (defaultRingtoneUri != null) {
            defaultRingtone = RingtoneManager.getRingtone(this, defaultRingtoneUri);

            if (defaultRingtone != null) {
                if (deviceInfo.getSdkVersion() >= Build.VERSION_CODES.LOLLIPOP) {
                    AudioAttributes attributes = new AudioAttributes.Builder()
                            .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                            .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build();
                    defaultRingtone.setAudioAttributes(attributes);
                } else {
                    defaultRingtone.setStreamType(AudioManager.STREAM_NOTIFICATION);
                }
                defaultRingtone.play();
            }
        }
    }
}

From source file:org.wso2.emm.agent.AlertActivity.java

/**
 * This method is used to start ringing the phone.
 *///from  w  w  w  .j av a 2  s.  c o m
@TargetApi(21)
private void startRing() {
    if (audio != null) {
        audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        audio.setStreamVolume(AudioManager.STREAM_RING, audio.getStreamMaxVolume(AudioManager.STREAM_RING),
                AudioManager.FLAG_PLAY_SOUND);

        defaultRingtoneUri = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE);

        if (defaultRingtoneUri != null) {
            defaultRingtone = RingtoneManager.getRingtone(this, defaultRingtoneUri);

            if (defaultRingtone != null) {
                if (deviceInfo.getSdkVersion() >= Build.VERSION_CODES.LOLLIPOP) {
                    AudioAttributes attributes = new AudioAttributes.Builder()
                            .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                            .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build();
                    defaultRingtone.setAudioAttributes(attributes);
                } else {
                    defaultRingtone.setStreamType(AudioManager.STREAM_NOTIFICATION);
                }
                defaultRingtone.play();
            }
        }
    }
}