




版權(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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 皖西衛(wèi)生職業(yè)學(xué)院《數(shù)字游戲角色設(shè)計(jì)》2023-2024學(xué)年第二學(xué)期期末試卷
- 幼兒園大班社會活動《課間十分鐘》教案(5篇)
- 2025年重慶市安全員知識題庫及答案
- 莆田學(xué)院《數(shù)據(jù)結(jié)構(gòu)(Java)》2023-2024學(xué)年第二學(xué)期期末試卷
- 天津中德應(yīng)用技術(shù)大學(xué)《商務(wù)數(shù)據(jù)分析》2023-2024學(xué)年第二學(xué)期期末試卷
- 濰坊學(xué)院《土地測量與評價》2023-2024學(xué)年第二學(xué)期期末試卷
- 邯鄲科技職業(yè)學(xué)院《風(fēng)電機(jī)組設(shè)計(jì)與制造》2023-2024學(xué)年第二學(xué)期期末試卷
- 長治幼兒師范高等??茖W(xué)?!额A(yù)算管理模擬》2023-2024學(xué)年第二學(xué)期期末試卷
- 2025年江西省建筑安全員《B證》考試題庫
- 2025年湖南省安全員《A證》考試題庫及答案
- 人教版四年級數(shù)學(xué)下冊《圖形的運(yùn)動(二)》試題(含答案)
- 《老年人權(quán)益保障法》
- 2025年交管12123駕駛證學(xué)法減分題庫與參考答案
- 2025下半年上海事業(yè)單位招考易考易錯模擬試題(共500題)試卷后附參考答案
- 天津市和平區(qū)2024-2025學(xué)年高一(上)期末質(zhì)量調(diào)查物理試卷(含解析)
- 《呼吸》系列油畫創(chuàng)作中詩意建構(gòu)的研究與實(shí)踐
- 客流統(tǒng)計(jì)系統(tǒng)施工方案
- 船舶制造設(shè)施安全生產(chǎn)培訓(xùn)
- SH∕T 3097-2017 石油化工靜電接地設(shè)計(jì)規(guī)范
- 基礎(chǔ)構(gòu)成設(shè)計(jì)全套教學(xué)課件
- Python程序設(shè)計(jì)基礎(chǔ)PPT(本科)完整全套教學(xué)課件
評論
0/150
提交評論