Last active
August 29, 2015 14:03
-
-
Save matheusjardimb/60d5d558befff4597332 to your computer and use it in GitHub Desktop.
Android Play incondicional sound
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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