java - Sound should only play once but plays twice instead -
i building app flash cards. when click "next" button plays sound(the name of card) , plays same sound if click on card. thing when click on "next" button plays sound twice, simultaneously, causing sound robotic. assume i'm calling sound twice accident don't know or how fix it. i've been looking on place can't find way fix this.
here code:
private string[] soundfile={"aa.m4a","bb.m4a... public void onclick(view arg0) {... //when btnplay clicked else if(arg0.getid()==r.id.imagenumber){ //call method playsound playsound(soundfile[screennumber].tostring()); }//end btnsound clicked //begin changecard private void changecard(int screen){ switch (screen){ case 0: imagenumber.setimageresource(aa); mediap2 = mediaplayer.create(this, r.raw.aa); break;... mediap2.start(); }//end changecard //begin playsound on click public void playsound(string soundname){ boolean mpplayingstatus; try{//try check mediaplayer status mpplayingstatus=mp.isplaying(); } catch (exception e){ mpplayingstatus=false; } if(mpplayingstatus==true){//if mediaplayer playing voice, stop play new voice mp.stop(); mp.release();//remove sound memory } else{ try { mp = new mediaplayer(); assetfiledescriptor afd = getassets().openfd(soundname); mp.setdatasource(afd.getfiledescriptor(), afd.getstartoffset(), afd.getlength()); mp.prepare(); mp.start();//play sound }//try block catch(exception e) { log.i("error playing sound: ", e.tostring()); } } }//end playsound
thanks help!
oh wow. figured out. whole time thought strictly issue sound turns out problem here:
if(arg0.getid()==r.id.btnprevious){ screennumber--;//minus 1 screennumber changenumber(screennumber); if(screennumber==0){ //disable btnprevious btnprevious.setenabled(false); }else{ //enable btnprevious btnprevious.setenabled(true); } changenumber(screennumber); btnnext.setenabled(true); }
where called changenumber(screennumber); btnnext.setenabled(true);
twice. silly mistake. anyway!
Comments
Post a Comment