基于AS30的音樂播放器設(shè)計(jì)_第1頁
基于AS30的音樂播放器設(shè)計(jì)_第2頁
基于AS30的音樂播放器設(shè)計(jì)_第3頁
基于AS30的音樂播放器設(shè)計(jì)_第4頁
基于AS30的音樂播放器設(shè)計(jì)_第5頁
已閱讀5頁,還剩6頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、flash3.0音樂播放器動畫課程過程課程名稱: 基于AS3.0的音樂播放器設(shè)計(jì) 院系: 電信學(xué)院 學(xué)號: 11340423 姓名: 李云 班級: 1134多媒體動漫 日期: 2012 年 12 月 15 基于AS3.0的音樂播放器設(shè)計(jì)一、 序言設(shè)計(jì)基于AS3.0的音樂播放器,實(shí)現(xiàn)對音樂的基本操作,并顯示歌詞。Photoshop cs4; flash cs4/ActionScript3.0;二、 作品結(jié)構(gòu)1. 文件結(jié)構(gòu) 2圖層結(jié)構(gòu)三、 設(shè)計(jì)步驟一、界面設(shè)計(jì) 1:上一首按鈕,實(shí)例名為prev_btn;2:暫停和播放按鈕重疊在一起,實(shí)例名分別為souPause和souPlay;3:下一首按鈕,實(shí)例

2、名next_btn;4:播放時間,實(shí)例名為songtime_txt;5:歌曲長度,實(shí)例名為songlenght_txt;6:歌詞,實(shí)例名為lrc_txt; 7:進(jìn)度滑塊,實(shí)例名progKnob_mc;8:進(jìn)度條,實(shí)例名為progBar_mc 9:靜音,實(shí)例名volumeIcon_mc;10:音量控制,實(shí)例名volumeSlider_mc;10:列表:實(shí)例名playList_cb;二、功能實(shí)現(xiàn) 1.從XML文件中載人歌曲和歌詞并提供給列表下拉var playList:XML = new XML();var xmlLoader:URLLoader = new URLLoader();var xml

3、Req:URLRequest = new URLRequest(playlist.xml);xmlLoader.load(xmlReq);var lrcList:XML = new XML();var lrcLoader:URLLoader = new URLLoader();var lrcReq:URLRequest = new URLRequest(lrclist.xml);lrcLoader.load(lrcReq);/將加載進(jìn)的xml播放列表信息提供給播放下拉列表xmlLoader.addEventListener(Event.COMPLETE, completeHandler);lr

4、cLoader.addEventListener(Event.COMPLETE, completeLrc);function completeHandler(evt:Event):voidplayList = XML(evt.target.data);playList_cb.dataProvider = new DataProvider(playList);loadSound(playList.song0.data);/E4X syntaxplayList_cb.selectedIndex = 0;currentSound = playList_cb.selectedIndex;functio

5、n completeLrc(evt:Event):voidlrcList = XML(evt.target.data);loadSound(lrcList.lrc0.data);2下拉列表改變事件playList_cb.addEventListener(Event.CHANGE, changeHandler);function changeHandler(evt:Event):voidif (playList_cb.selectedItem.data != )currentSound = playList_cb.selectedIndex;loadSound(playList_cb.selec

6、tedItem.data);loadLrc(lrcList.lrccurrentSound.data);3.加載聲音,播放聲音/加載音樂函數(shù)function loadSound(file:String):voidreq = new URLRequest(file);pauseSound();sound = new Sound(req);sound.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);playSound();stage.addEventListener(Event.ENTER_FRAME,SoundPlayin

7、g);/播放音樂函數(shù)(缺省pos參數(shù)為0)function playSound(pos:Number = 0):voidsoundControl = sound.play(pos);soundControl.addEventListener(Event.SOUND_COMPLETE, nextSound);/播放下一首volumeAdjust();/音量初始化souPlay.visible=false;souPause.visible=true;progKnob_mc.addEventListener(Event.ENTER_FRAME, progKnobUpdate);4.歌詞 functi

8、on loadLrc(file:String):void req1=new URLRequest(file); var loader:URLLoader=new URLLoader(); loader.load(req1); loader.addEventListener(Event.COMPLETE,LoadFinish);歌詞算法:function LoadFinish(evt:Event):void LRCarray=new Array(); var list:String=evt.target.data; var listarray:Array=list.split(n); var r

9、eg:RegExp=/0-50-9:0-50-9.0-90-9/g; for (var i=0; ilistarray.length; i+) var info:String=listarrayi; var len:int=info.match(reg).length; var timeAry:Array=info.match(reg); var lyric:String=info.substr(len*10); for (var k:int=0; kparaB.timer) return 1; if (paraA.timerparaB.timer) return -1; return 0;

10、5.顯示歌詞算法 function SoundPlaying(evt:Event):void for (var i=1; iLRCarray.length; i+) if (soundControl.positionLRCarrayi.timer) lrc_txt.text=LRCarrayi-1.lyric; break; lrc_txt.text=LRCarrayLRCarray.length-1.lyric; 6播放控制 /播放按鈕行為和狀態(tài)控制souPause.visible=false;souPlay.visible = true;prev_btn.visible = true;ne

11、xt_btn.visible = true;souPlay.addEventListener(MouseEvent.CLICK, soundPlay);souPause.addEventListener(MouseEvent.CLICK, soundPause);function soundPlay(e:MouseEvent):voidplaySound(soundControl.position);function soundPause(e:MouseEvent):voidpauseSound();prev_btn.addEventListener(MouseEvent.CLICK, pre

12、vSound);function prevSound(evt:MouseEvent):voidcurrentSound -;if(currentSound playList.song.length() - 1)currentSound = 1;playList_cb.selectedIndex = currentSound;loadSound(playList.songcurrentSound.data);loadLrc(lrcList.lrccurrentSound.data);7.音量控制 volumeDegrees = volumeSlider_mc.volumeKnob_mc.x;/初

13、始化volumeSlider_mc.volumeKnob_mc.visible = true;volumeSlider_mc.volumeKnob_mc.addEventListener(MouseEvent.MOUSE_DOWN, volumeKnobStartDrag);function volumeKnobStartDrag(evt:MouseEvent):voidrec = new Rectangle(volumeSlider_mc.spanning_mc.x, volumeSlider_mc.volumeBar_mc.y, volumeSlider_mc.spanning_mc.wi

14、dth + 1, 0);volumeSlider_mc.volumeKnob_mc.startDrag(false, rec);stage.addEventListener(MouseEvent.MOUSE_MOVE, volumeAdjust);stage.addEventListener(MouseEvent.MOUSE_UP, volumeKnobStopDrag);function volumeKnobStopDrag(evt:MouseEvent):voidvolumeSlider_mc.volumeKnob_mc.stopDrag();if(volumeSlider_mc.volu

15、meKnob_mc.x != 0)volumeDegrees = volumeSlider_mc.volumeKnob_mc.x;stage.removeEventListener(MouseEvent.MOUSE_UP, volumeKnobStopDrag);volumeSlider_mc.volumeKnob_mc.removeEventListener(MouseEvent.MOUSE_MOVE, volumeAdjust);function volumeAdjust(evt:MouseEvent = null):voidvolumeSlider_mc.volumeBar_mc.wid

16、th = volumeSlider_mc.volumeKnob_mc.x;if(volumeSlider_mc.volumeKnob_mc.x = 0)volumeIcon_mc.gotoAndStop(mute);elsevolumeIcon_mc.gotoAndStop(unmute);/volumeDegrees = volumeSlider_mc.volumeKnob_mc.x;if (soundControl != null)xform = soundControl.soundTransform;xform.volume = volumeSlider_mc.volumeKnob_mc

17、.x / volumeSlider_mc.spanning_mc.width;soundControl.soundTransform = xform;volumeIcon_mc.visible = true;volumeIcon_mc.addEventListener(MouseEvent.CLICK, switchVolumeStatus);function switchVolumeStatus(evt:MouseEvent):voidif(volumeIcon_mc.currentLabel = unmute)volumeDegrees = volumeSlider_mc.volumeKn

18、ob_mc.x;volumeSlider_mc.volumeKnob_mc.x = 0;volumeAdjust();volumeIcon_mc.gotoAndStop(mute);elsevolumeSlider_mc.volumeKnob_mc.x = volumeDegrees;volumeAdjust();volumeIcon_mc.gotoAndStop(unmute);8.進(jìn)度控制 /進(jìn)度條控制progKnob_mc.visible = true;function progKnobUpdate(evt:Event):voidsongtime_txt.text=getTimeFmt(

19、soundControl.position);songlenght_txt.text=getTimeFmt(sound.length);var pos:Number = (progBar_mc.width - progKnob_mc.width) * soundControl.position / sound.length;if(!isNaN(pos)progKnob_mc.x = progBar_mc.x + pos;elseprogKnob_mc.x = progBar_mc.x;progKnob_mc.addEventListener(MouseEvent.MOUSE_DOWN, pro

20、gKnobStartDrag);function progKnobStartDrag(evt:MouseEvent):voidif(sound != null)pauseSound();rec = new Rectangle(progBar_mc.x, progBar_mc.y, progBar_mc.width - progKnob_mc.width, 0);progKnob_mc.startDrag(false, rec);stage.addEventListener(MouseEvent.MOUSE_UP, progKnobStopDrag);function progKnobStopD

21、rag(evt:MouseEvent):voidprogKnob_mc.stopDrag();var pos:Number = sound.length * (progKnob_mc.x - progBar_mc.x) / (progBar_mc.width - progKnob_mc.width);playSound(pos);stage.removeEventListener(MouseEvent.MOUSE_UP, progKnobStopDrag);9.頻譜算法 /視覺化音頻var ba:ByteArray = new ByteArray();var gr:Sprite = new Sprite();gr.x = 255;gr.y = 285;addChild(gr);var time:Timer = new Timer(50); time.addEventListener(TimerEvent.TIMER,timerHandler); time.star

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論