Skip to content

Instantly share code, notes, and snippets.

@matheusjardimb
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matheusjardimb/60d5d558befff4597332 to your computer and use it in GitHub Desktop.
Save matheusjardimb/60d5d558befff4597332 to your computer and use it in GitHub Desktop.
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