flash8 做音乐播放器暂停按钮代码
来源:百度知道 编辑:UC知道 时间:2024/07/08 10:02:30
控制声音的播放、暂停和停止
_root.createEmptyMovieClip("_mc", _root.getNextHighestDepth());
var mySound:Sound=new Sound(_mc);
mySound.loadSound("02.mp3", true);
mySound.stop();
var playedPosition:Number;
var stoped:Boolean=true;
var paused:Boolean=false;
//停止按钮,单击按钮停止播放
stop_btn.onRelease=function(){
stoped=true;
paused=false;
mySound.stop();
}
//暂停按钮,控制声音的暂停与继续播放
pause_btn.onRelease=function(){
if(!paused && !stoped){ //如果不是暂停也不是停止的话
paused=true;
playedPosition=mySound.position; //记录声音播放的当前位置
mySound.stop();
}else if(paused && !stoped){//如果声音已经暂停,就从上一次记录的位置开始播放
paused=false;
mySound.start(playedPosition/1000); //position记录的单位为毫秒,所以要除以1000
}
}