import flash.events.Event;
import fl.events.SliderEvent

var sound:Sound=new Sound(new URLRequest("1.mp3"));  //載入1.mp3
var soundCtl:SoundChannel=new SoundChannel();  //宣告SoundChannel

sound.addEventListener(Event.COMPLETE,$complete);  //音樂載入完成
function $complete($e:Event):void{  //音樂載入完成的執行函數
 soundCtl=sound.play();  //播放(位置=0,重覆次數:無限次)
 soundCtl.addEventListener(Event.SOUND_COMPLETE,$soundComplete);  //播放完畢的監聽事件
 stop_btn.addEventListener(MouseEvent.CLICK,$stop);  //停止鍵的監聽
 play_btn.addEventListener(MouseEvent.CLICK,$play);  //播放鍵的監聽
 pause_btn.addEventListener(MouseEvent.CLICK,$pause);//暫停鍵的監聽
}
function $soundComplete($e:Event){  //播放完畢的執行函數
 if(cont<5){  //共有5首mp3
  cont+=1; //跳下一首
 }else{
  cont=1;  //跳第1首
 }
 soundCtl.stop();  //先停止上一首mp3
 sound=new Sound(new URLRequest(cont + ".mp3"));  //載入下一首mp3
 soundCtl=sound.play();        //播放
 soundCtl.addEventListener(Event.SOUND_COMPLETE,$soundComplete);  //播放完畢的監聽事件
}
function $stop($e:MouseEvent):void{  //停止的執行函數
 soundCtl.stop();  //音樂停止
 setre=0;          //音樂位置:0,所以按「播放」時,會從頭播放
}

function $play($e:MouseEvent):void{  //播放的執行函數
 soundCtl=sound.play(setre,0);
}

function $pause($e:MouseEvent):void{  //暫停的執行函數
 setre=soundCtl.position;  //紀錄音樂的位置
 soundCtl.stop();          //音樂停止
}

如需範例檔,請MAIL:css6666@yahoo.com.tw

如果您認為內容不錯,也請幫我點個廣告,謝謝。

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 css6 的頭像
    css6

    美奇電腦

    css6 發表在 痞客邦 留言(0) 人氣()