I have a button widget. I want to play sound when the button is pressed and when the user releases the button (takes his finger off the button) the audio playback should be stopped. I have used the following code but it doesn’t work.
public boolean onTouch(View v, MotionEvent me) {
int action = me.getAction();
if(action == MotionEvent.ACTION_DOWN) {
playSound();
} else if (action == MotionEvent.ACTION_UP) {
stopSound();
}
return false;
}
Is
stopSound()being called? I think you need to return true in theaction == MotionEvent.ACTION_DOWNblock to tell the system that you handled the event.