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 trialRory Callendar
1,014 PointsRepurposed Crystal Ball Sound Issue
I re-purposed my Crystal Ball to be a random name selector to use in my classroom. My new sound effect however plays twice (overlapping)...I think because it is detecting two onShake events. Is there a way to make sure my sound plays once only by itself until the whole sound has been played to the end?
Also, anyone know where to start if I want to customize my name selector for each of my classes? I could create 5 different apps and enter names manually, but I'd rather be able to grab the names from our school's software (Pinnacle GradeBook) on one app with the click of a button.
1 Answer
Ben Jakuben
Treehouse TeacherHi Rory,
I love this change! Thanks for sharing!
There is a MediaPlayer method called isPlaying()
that you could probably use to prevent the sound from playing twice. I have some code I can paste in, but why don't you try getting it to work yourself, first? Stop back in and let us know if you get it or if you need more help. Here are some guidelines:
- Right now we are declaring the MediaPlayer variable in the
playSound()
method. Move the declaration so thatplayer
is a class member variable. That way it's the same variable being used each timeplaySound()
is called (as opposed to having new ones created each time). - With that changed, you could then use the
isPlaying()
method to control how the player is created and started inside theplaySound()
method.
Hope this helps!