




已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
二维动画课程设计课程设计报告课程名称: 基于AS3.0的音乐播放器设计 院系: 物理与电子信息学院 学号: 070804017 姓名: 刘清亮 班级: 07数字媒体 日期: 2010 年 12 月 基于AS3.0的音乐播放器设计一、 序言设计基于AS3.0的音乐播放器,实现对音乐的基本操作,并显示歌词。Photoshop cs4; flash cs4/ActionScript3.0;二、 作品结构1. 文件结构 2图层结构 三、 设计步骤一、界面设计 1:上一首按钮,实例名为prev_btn;2:暂停和播放按钮重叠在一起,实例名分别为souPause和souPlay;3:下一首按钮,实例名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;二、功能实现 1.从XML文件中载人歌曲和歌词并提供给列表下拉var playList:XML = new XML();var xmlLoader:URLLoader = new URLLoader();var xmlReq: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);lrcLoader.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;function 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.selectedItem.data);loadLrc(lrcList.lrccurrentSound.data);3.加载声音,播放声音/加载音乐函数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,SoundPlaying);/播放音乐函数(缺省pos参数为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.歌词 function 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 reg: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; 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播放控制 /播放按钮行为和状态控制souPause.visible=false;souPlay.visible = true;prev_btn.visible = true;next_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, prevSound);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;/初始化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.width + 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.volumeKnob_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.width = 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.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.volumeKnob_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(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, progKnobStartDrag);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 progKnobStopDrag(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 = 88;gr.y = 285;addChild(gr);var time:Timer = new Timer(50); time.addEventListener(TimerEvent.TIMER,timerHandler); time.start(); fun
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 适应潮流趋势调整2025年注册会计师考试复习策略试题及答案
- 甘肃省兰州市2025年高三适应性调研考试语文试题含解析
- 了解2025年证券从业资格证考试的职业路径规划试题及答案
- 国际金融理财师考试国家经济政策分析试题及答案
- 逐步深入掌握2025年注册会计师考试知识要点试题及答案
- 微生物检验对提升医疗质量的影响试题及答案
- 部门2025年终工作总结(6篇)
- 总店长述职报告
- 2025年行业竞争意识试题及答案
- 微生物技术与临床医学结合的未来展望试题及答案
- 水下潜水艇课件
- 糖尿病酮症酸中毒护理
- 36 阶段统计项目风险管理表甘特图
- 陕西气象部门招聘笔试真题2024
- 2025-2030中国电信增值行业运行状况与发展前景预测研究报告
- 学校中层干部选拔任用实施方案
- 2025年吉林铁道职业技术学院单招职业倾向性考试题库含答案
- 品牌总监的面试题及答案
- 电气工程及其自动化毕业论文-基于PLC的高空作业车电控系统设计
- 贵州高品质住宅设计导则
- 装修公司设计经理述职报告
评论
0/150
提交评论