Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android Play incondicional sound
final String packageName = getPackageName();
Uri alarmSound = Uri.parse("android.resource://" + packageName + "/" + R.raw.my_audio);
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(this, alarmSound);
mp.setAudioStreamType(AudioManager.STREAM_ALARM);
mp.prepare();
mp.start();
AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
final int streamMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM);
mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, streamMaxVolume, AudioManager.FLAG_PLAY_SOUND);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.