Android newbie here, this is my first application... should be very simple but I just want to make sure I'm starting on the right foot and not building something inelegant...

I have an ImageButton that should only play a sound while it is depressed. As soon as you lift your finger up the sound stops. Each time you touch it the playback starts from the beginning of the sound.

I have it working but sometimes I get MediaPlayer errors if you click it quickly and for short durations. I could install an error handler that resets the sound and data source and re-prepares it, but that seems wasteful if I just need different logic to avoid the errors in the first place.

Here is what I have for the button's onTouch handler, from onCreate():

Another thing is that originally I was pausing the sound instead of stopping it. But the seekTo call is asynchronous so I was ending up with audible clicks at the beginning of the subsequent presses of the button. There may be a better way to do this altogether so I'm wide open for suggestions.

I looked at SoundPool at first but I didn't see a way to get notified of when the sound finished playing... I have other buttons where you touch them and they stay depressed on their own until the sound completes and then they pop back up. This is working fine with MediaPlayer currently. I supposed I could do the one button type with MediaPlayer and the other button type with SoundPool, but I was hoping for a more uniform solution.