How yo play rington/alarm sound in Android
Posted
by Federico
on Stack Overflow
See other posts from Stack Overflow
or by Federico
Published on 2010-04-11T18:28:45Z
Indexed on
2010/04/11
18:33 UTC
Read the original article
Hit count: 455
I have been looking everywhere how to play a $#@&! rington/alarm sound in android.
I press a button and I want to play a rington/alarm sound. I could not find a easy, strsight forward sample... YES! I already looked at Alarm clock source code... but it is not straight forward and I cannot compile it neither.
I cannot make this work:
Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(this, alert); final AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) { player.setAudioStreamType(AudioManager.STREAM_ALARM); player.setLooping(true); player.prepare(); player.start(); }
I get this error 04-11 17:15:27.638: ERROR/MediaPlayerService(30): Couldn't open fd for content://settings/system/ringtone
So.. please if somebody knows how to play a default rington/alarm let me know.
I prefer not to upload any file. Just play a default rington.
Thanks,
Federico
© Stack Overflow or respective owner