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

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -