Search in sources :

Example 1 with AsyncPlayer

use of android.media.AsyncPlayer in project Shuttle by timusus.

the class MediaButtonIntentReceiver method beep.

/**
     * Play a beep sound.
     */
private static void beep(Context context) {
    if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("pref_headset_beep", true)) {
        AsyncPlayer beepPlayer = new AsyncPlayer("BeepPlayer");
        Uri beepSoundUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getResources().getResourcePackageName(R.raw.beep) + '/' + context.getResources().getResourceTypeName(R.raw.beep) + '/' + context.getResources().getResourceEntryName(R.raw.beep));
        if (ShuttleUtils.hasMarshmallow()) {
            AudioAttributes audioAttributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).setContentType(AudioAttributes.CONTENT_TYPE_MUSIC).build();
            beepPlayer.play(context, beepSoundUri, false, audioAttributes);
        } else {
            beepPlayer.play(context, beepSoundUri, false, AudioManager.STREAM_MUSIC);
        }
    }
}
Also used : AsyncPlayer(android.media.AsyncPlayer) AudioAttributes(android.media.AudioAttributes) Uri(android.net.Uri)

Aggregations

AsyncPlayer (android.media.AsyncPlayer)1 AudioAttributes (android.media.AudioAttributes)1 Uri (android.net.Uri)1