java - I get error (1, 19) when tapping on multiple buttons that play sound -


it works few buttons, when tap 6 of them work. ones don't work give error (1, -19). media player state wrapper set up, if need use states of "mp"s, let me know.

public class soundfile {      public soundfile(final activity activity, final string soundfile, int imgbuttonid, arraylist<mediaplayerstatewrapper> mps) {          this.mp = new mediaplayerstatewrapper();         try {           this.afd = activity.getassets().openfd(soundfile + ".mp3");         } catch (ioexception e) {             e.printstacktrace();         }          this.allmps = mps;         mps.add(this.mp);         this.position = (imagebutton) activity.findviewbyid(imgbuttonid);          this.position.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 try {                     mp.reset();                     mp.setdatasource(afd.getfiledescriptor(), afd.getstartoffset(), afd.getlength());                     mp.prepareasync();                     mp.start();                 }catch (exception ex){                     ex.printstacktrace();                 } .... 

you have add onpreparedlistener. here did , worked.

 try {                  mp = new mediaplayer();                  mp.reset();                 try {                     mp.setdatasource(afd.getfiledescriptor(), afd.getstartoffset(), afd.getlength());                 } catch (ioexception e) {                     e.printstacktrace();                 }                 mp.setoncompletionlistener(new mediaplayer.oncompletionlistener() {                     @override                     public void oncompletion(mediaplayer mediaplayer) {                         mp.release();                      }                 });                   mp.setonpreparedlistener(new onpreparedlistener() {                     @override                     public void onprepared(mediaplayer mpm) {                         mpm.start();                          mp.start();                       }                 });                 mp.prepareasync();               } catch (exception ex) {                 ex.printstacktrace();             }           }     }); }  } 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -