java - How to rapidly play a sound when button is clicked(android) -


i'm trying play sound each time, button clicked. sound played need play every single time(like sound played when type something), problem is, mine isn't playing always. think because button clicked little delay.

    new mediaplayer sound = new mediaplayer().create(getapplicationcontext(), r.raw.sound); button.setontouchlistener(new view.ontouchlistener() {     @override     public boolean ontouch(view v, motionevent event) {         if (x >= ps.getx() && x < (ps.getx() + squares.getwidth()) &&                 y >= ps.gety() && y < (ps.gety() + squares.getheight())) {             ps.setres(psquareoffres);             ps.setx(ps.getx() - squares.getwidth());             ps.sety(ps.gety() - squares.getheight());             ps.settouched(true);             ps.lock(true);             touchlimita = system.currenttimemillis();             timer = 3;             sound.start();             break;         }         return false;     } 

i glad of advice can give :).

if need low latency playback should use soundpool


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -