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

[AS3]as3的运用Sound类实现播放/暂停/停止mp3音乐播放器源代码

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

[AS3]as3的运用Sound类实现播放/暂停/停止mp3音乐播放器

  1. //number that is redefined when the pause button is hit 
  2. var pausePoint:Number = 0.00; 
  3. //a true or false value that is used to check whether the sound is currently playing 
  4. var isPlaying:Boolean; 
  5.  
  6. //think of the soundchannel as a speaker system and the sound as an mp3 player 
  7. var soundChannel:SoundChannel = new SoundChannel(); 
  8. var sound:Sound = new Sound(new URLRequest("CuPLayer_com/cuplayer.mp3")); 
  9.  
  10. //your stop button and play/pause buttons 
  11. xstop.addEventListener(MouseEvent.CLICK, clickStop); 
  12. xplay.addEventListener(MouseEvent.CLICK, clickPlayPause); 
  13. soundsoundChannel = sound.play(); 
  14. isPlaying = true
  15. function clickPlayPause(evt:MouseEvent) { 
  16.     if (isPlaying) { 
  17.         pausePoint = soundChannel.position; 
  18.         soundChannel.stop(); 
  19.         isPlaying = false
  20.     } else { 
  21.         soundsoundChannel = sound.play(pausePoint); 
  22.         isPlaying = true
  23.     } 
  24.  
  25. function clickStop(evt:MouseEvent) { 
  26.     if (isPlaying) { 
  27.         soundChannel.stop(); 
  28.         isPlaying = false
  29.     } 
  30.     pausePoint = 0.00; 

 

ABOUT US
宜昌农人网络科技有限公司

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

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

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