Android : How can I make MediaPlayer sound to be continued? Not looping

on Sunday, September 14, 2014


I have a MediaPlayer for onTouchEvent(). So every time when I touch the screen its play the sound for two seconds. The problem is, even I continued touching on the screen, I still have to wait until the program finish the first two seconds sound then play it next time.


But I want it to be like every time I touch the screen, no matter the sound from first tap is playing or not, it have to play a new sound.


Here is the code I have:



public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
MediaPlayer sound= MediaPlayer.create(getContext(), R.raw.boo);
sound.start();
pointX.add(event.getX());
pointY.add(event.getY());
postInvalidate();
break;

0 comments:

Post a Comment