宜昌本地软件开发与弱电工程服务商
项目咨询 · 快速响应
您当前的位置: > 博客2 > AS2与AS3技术

[AS3]as3加载外部mp3制作mp3音乐播放器源代码实例

2016-10-13 00:16:48 点击量:14 标签: 收藏本文

[AS3]as3加载外部mp3制作mp3音乐播放器源代码实例

  1. var SoundState:Boolean; 
  2.  
  3. var sndChannel:SoundChannel; 
  4. var snd:Sound = new Sound(); 
  5. snd.addEventListener(ProgressEvent.PROGRESS, ProgressHandler); 
  6. snd.addEventListener(Event.COMPLETE, CompleteHandler); 
  7. snd.load(new URLRequest("showroom.mp3")); 
  8.  
  9. var outputText:TextField=new TextField(); 
  10. outputText.width = 500
  11. outputText.height = 20
  12. addChild(outputText); 
  13. //cuplayer.com提示,加载进度 
  14. function ProgressHandler(e:ProgressEvent):void { 
  15.     outputText.text = "Loading: " + Math.round(100 * e.bytesLoaded / e.bytesTotal); 
  16.     trace("Loading: " + Math.round(100 * e.bytesLoaded / e.bytesTotal)); 
  17. function CompleteHandler(e:Event):void { 
  18.     outputText.text = "Sound loaded - click the stage to play and stop"
  19.     snd.removeEventListener(ProgressEvent.PROGRESS, ProgressHandler); 
  20.     snd.removeEventListener(Event.COMPLETE, CompleteHandler); 
  21.     stage.addEventListener(MouseEvent.CLICK, clickHandler); 
  22. //cuplayer.com提示,暂停、播放动作 
  23. function clickHandler(e:Event):void { 
  24.     SoundState=!SoundState; 
  25.     trace(SoundState); 
  26.     if (SoundState) { 
  27.         outputText.text ="PLAY"
  28.         sndsndChannel=snd.play(pausePosition); 
  29.     } else { 
  30.         var pausePosition:int = sndChannel.position; 
  31.         outputText.text ="PAUSE"
  32.         sndsndChannel=snd.play(pausePosition); 
  33.     } 
ABOUT US
宜昌农人网络科技有限公司

我们是一家提供综合软件外包与弱电工程服务的技术公司。

业务涵盖定制软件、管理系统、网站、小程序、APP、系统集成、网络布线、监控安防、门禁、机房建设及长期技术维护。

公司地址:湖北省宜昌市伍家岗区东站二路6号三峡(宜昌)大数据产业园海洋馆二楼A203室