




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、flash3.0音樂播放器動畫課程過程課程名稱: 基于AS3.0的音樂播放器設計 院系: 電信學院 學號: 11340423 姓名: 李云 班級: 1134多媒體動漫 日期: 2012 年 12 月 15 基于AS3.0的音樂播放器設計一、 序言設計基于AS3.0的音樂播放器,實現(xiàn)對音樂的基本操作,并顯示歌詞。Photoshop cs4; flash cs4/ActionScript3.0;二、 作品結構1. 文件結構 2圖層結構三、 設計步驟一、界面設計 1:上一首按鈕,實例名為prev_btn;2:暫停和播放按鈕重疊在一起,實例名分別為souPause和souPlay;3:下一首按鈕,實例
2、名next_btn;4:播放時間,實例名為songtime_txt;5:歌曲長度,實例名為songlenght_txt;6:歌詞,實例名為lrc_txt; 7:進度滑塊,實例名progKnob_mc;8:進度條,實例名為progBar_mc 9:靜音,實例名volumeIcon_mc;10:音量控制,實例名volumeSlider_mc;10:列表:實例名playList_cb;二、功能實現(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);/將加載進的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.進度控制 /進度條控制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)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 陜西學前師范學院《檢測技術實驗》2023-2024學年第二學期期末試卷
- 陜西工商職業(yè)學院《混合動力汽車結構原理》2023-2024學年第二學期期末試卷
- 陜西理工大學《土體工程穩(wěn)定性分析》2023-2024學年第一學期期末試卷
- 陜西省咸陽市永壽縣中學2025年高三4月調研測試(二診)物理試題試卷含解析
- 陜西省商洛市洛南中學2025年七校聯(lián)考高考歷史試題一模試卷含解析
- 陜西省涇陽縣階段性自測題2025屆數(shù)學三下期末學業(yè)質量監(jiān)測模擬試題含解析
- 幼兒園海灘課件
- 陜西科技大學鎬京學院《教學技術與媒體》2023-2024學年第二學期期末試卷
- 保姆合同樣本照顧癱瘓老人
- 個人投資回報合同標準文本
- 2025-2030氣體檢測儀器行業(yè)市場深度調研及前景趨勢與投資研究報告
- 受限空間作業(yè)施工方案
- (一模)2025年廣州市普通高中畢業(yè)班綜合測試(一)政治試卷(含答案)
- 太乙課堂游戲最終版
- 大數(shù)據分析和可視化平臺使用手冊
- 2025年骨科入科考試題及答案
- 2025上半年江西贛州市人民醫(yī)院招考聘用工作人員自考難、易點模擬試卷(共500題附帶答案詳解)
- 2025年武漢鐵路橋梁職業(yè)學院單招職業(yè)技能測試題庫必考題
- DB32T 5003-2025小微型和勞動密集型工業(yè)企業(yè)現(xiàn)場安全管理規(guī)范
- 2025年度家暴離婚協(xié)議書范本制作與使用
- 課件:《魯濱遜漂流記》
評論
0/150
提交評論