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

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

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

javascript - Restarting Supervisor and effect on FlaskSocketIO -