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);
}
}
}
Aggregations