Flash製作簡單MP3播放器

來源:互聯網
上載者:User

  效果示範:

 點擊這裡下載源檔案

  首先建立幾個按鈕,放在第一楨,點擊按鈕在按鈕上寫下如下代碼:

on(release){
建立一個函數,使音樂檔案載入到25%才開始播放,要不然從網上載入的時候會卡。
function zairu(){
if(b>=25){
mysound.start(0,10);
如果載入到25%就清除。
clearInterval(poll);
}
}
poll=setInterval(zairu,100);
yinyue("你要載入的MP3地址");
}



  回到主情境,建立2個動態文本,變數名分別命為txt1,txt2,txt3,

 

function yinyue(name){
建立聲音對象,方便控制聲音
mysound=new Sound(this);
載入聲音
mysound.loadSound(name,true);
在這裡先停止聲音,不然聲音會載入到能啟動解壓程式時自動播放
mysound.stop(name);
}
function loading(){
已載入聲音大小
l=mysound.getBytesLoaded();
聲音總大小
m=mysound.getBytesTotal();
b=int(l/m*100);
txt1=b+"%";
txt2=int(l/1000)/1000+"M"+"/"+int(m/1000)/1000+"M";
已播放聲音時間
time=int(mysound.position/1000);
聲音總時間
time2=int(mysound.duration/1000);
s1=time;
if(s1<10){
s1="0"+s1;
}
txt3="已播放: "+s1+"秒";
loading21.loading3._xscale=b;
設定聲音的音量大小,
mysound.setVolume((huakuai2.huakuai._x+50)*2);
}
定時器觸發時間為100毫秒一次,使上面設定的變數不斷更新
setInterval(loading,100);

建立播放,暫停,快進,快退按鈕分別寫AS

on(release){
this.mysound.start(this.mysound.position/1000,1);
}
on(release){this.mysound.stop();}
on(release){
this.mysound.start((this.mysound.position/1000)+10,1);
}
on(release){
this.mysound.start((this.mysound.position/1000)-10,1);
}



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.