actionscript 3 - AS3 pause button doesn't play paused song from array -
i have flash mp3 player play, pause , next button on 1 frame.
songs stored in array.
everything works fine except pause button. pauses music
, save song position in variable. when click on pause
button again song supposed play saved song position
does. problem play first song in array. not
song paused. have tried find solution on google. but
topics find mp3 players played 1 song.
here code. thanks.
var i:number = 0; var mymusic:sound = new sound(); var mysongs:array = ["kalimba.mp3","sleep away.mp3","maid flaxen hair.mp3"]; var soundfile:urlrequest = new urlrequest(mysongs[i++]); var channel:soundchannel = new soundchannel(); var stransform:soundtransform = new soundtransform(); var songposition:number; var mycontext:soundloadercontext = new soundloadercontext(5000); mymusic.load(soundfile, mycontext); btnplay.addeventlistener(mouseevent.click, playmusic); btnnext.addeventlistener(mouseevent.click, nextmusic); btnpause.addeventlistener(mouseevent.click, pausemusic); channel.addeventlistener(event.sound_complete, nextmusic); function playmusic(evt:mouseevent):void { channel = mymusic.play(songposition); channel.addeventlistener(event.sound_complete, nextmusic); } function nextmusic(evt:event):void { channel.stop(); var mymusic:sound = new sound(); var mysongs:array = ["kalimba.mp3","sleep away.mp3","maid flaxen hair.mp3"]; var soundfile:urlrequest = new urlrequest(mysongs[i]); mymusic.load(soundfile, mycontext); channel = mymusic.play(i); channel.addeventlistener(event.sound_complete, nextmusic); if(i==mysongs.length-1) { i=0; } else { i++; } } var paused:boolean = false; function pausemusic(evt:mouseevent):void { if(paused==false) { songposition = channel.position; channel.stop(); paused = true; } else if(paused==true) { channel = mymusic.play(songposition); paused = false; } }
you shouldn't keep adding channel.addeventlistener(event.sound_complete, nextmusic);
beacuse sound_complete events fired when pause.
adding eventlistener once should suffice anyway.
Comments
Post a Comment