Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Annika Noren
26,930 PointsIs there a default alarm sound that I can use for Android Studio app?
I am writing an app on Android Studio, while watching my Treehouse videos on Java Objects. Lots to keep me busy.
I would like an alarm (or beep or something, the sound is not the priority) to go off for a few seconds once a countdown timer expires. I've got the countdown timer part working. After searching around the web, my thought is to use the following lines of code for the alarm part:
final MediaPlayer mp = MediaPlayer.create(this, R.raw,AUDIO_FILE_HERE); mp.start();
I've got a raw directory (it's empty), but can not figure out find or how to get an audio file in there. Or how I could access a default alarm or ringtone. I think the audio file only needs to be a few seconds long or I will have to figure out how to end the MediaPlayer after a few seconds (that would be my next challenge.)
I could be way off on my use of MediaPlayer - I'm a newbie, just trying to learn.
3 Answers
Seth Kroger
56,416 PointsIf you have an audio file you can just copy it over to res/raw just like you would copy an image over to the res/drawable-*dpi folders.
If you want the default notification or ringtone sounds it's Settings.System.DEFAULT_NOTIFICATION_URI, Settings.System.DEFAULT_ALARM_ALERT_URI or Settings.System.DEFAULT_RINGTONE_URI in place of R.raw.whatever.
Annika Noren
26,930 PointsHi Seth, I don't have an audio file to put into my raw directory. I'm unsure of how to go about getting that.
I tried the System.Settings.DEFAULT_NOTIFICATION_URI, so my code is now:
final MediaPlayer mp = MediaPlayer.create(this, System.Settings.DEFAULT_NOTIFICATION_URI); mp.start();
But there is an error with .Settings - "Cannot resolve symbol 'Settings'".
Any other thoughts? Am I overlooking something?
Thank you for replying.
Annika
Seth Kroger
56,416 PointsI'm sorry, it looks like wrote it backwards by mistake. It should be Settings.System, not System.Settings
Annika Noren
26,930 PointsYeah,that didn't work either. I'll focus on something else for a while. Thank you for the input.