[AS3]AS3写的mp3播放器源代码示例参考
[AS3]AS3写的mp3播放器源代码示例参考
[AS3]AS3写的mp3播放器源代码示例参考
- package {
- import flash.media.Sound;
- import flash.media.SoundChannel;
- import flash.media.SoundLoaderContext;
- import flash.media.SoundMixer;
- public class MediaPlayerCore {
- private var sound:Sound;
- private var soundCh:SoundChannel;
- private var soundCon:SoundLoaderContext;
- private var position:Number;
- private var isPlaying:Boolean;
- private var isPause:Boolean;
- private static var BUFFERTIME:Number = 10000;
- public function MediaPlayerCore()
- {
- isPause = false;
- isPlaying = false;
- SoundMixer.bufferTime = BUFFERTIME;
- }
- //cuplayer.com提示:创建一个声音对象
- //@param url 媒体地址
- // @param playNow 是否马上播放,默认为真
- public function createSound(url:String,playNow:Boolean = true):void
- {
- dispose();
- sound = new Sound();
- sound.load(new URLRequest(url));
- sound.addEventListener(IOErrorEvent.IO_ERROR,errorHandler);
- if(playNow)
- play();
- }
- //cuplayer.com提示:播放
- //@param offset 声音从哪开始
- public function play(offset:Number = 0):void
- {
- if(isPause)
- soundsoundCh = sound.play(position);
- else
- soundsoundCh = sound.play(offset);
- isPlaying = true;
- isPause = false;
- }
- //cuplayer.com提示:暂停
- public function pause():void
- {
- if(isPlaying)
- {
- position = soundCh.position;
- stop();
- isPause = true;
- }
- }
- //cuplayer.com提示:停止
- public function stop():void
- {
- if(isPlaying)
- {
- soundCh.stop();
- isPlaying = false;
- }
- }
- //cuplayer.com提示:播放位置
- public function get Position():Number
- {
- if(soundCh == null)
- return 0;
- return Math.round(soundCh.position);
- }
- //cuplayer.com提示:声音对象长度
- public function get Length():Number
- {
- if(sound == null)
- return 0;
- return Math.round(sound.length*sound.bytesTotal/sound.bytesLoaded);
- }
- //cuplayer.com提示:声音对象总共字节
- public function get BytesTotal():Number
- {
- if(sound == null)
- return 0;
- return sound.bytesTotal;
- }
- //cuplayer.com提示:声音对象加载字节
- public function get BytesLoaded():Number
- {
- if(sound == null)
- return 0;
- return sound.bytesLoaded;
- }
- //cuplayer.com提示:设置缓冲时间
- public function set BufferTime(time:Number):void
- {
- SoundMixer.bufferTime=time;
- }
- //中途换歌的时候用的
- private function dispose():void
- {
- if(sound == null)
- return ;
- if(sound.isBuffering)
- sound.close();
- stop();
- sound = null;
- }
- // cuplayer.com提示:处理错误用
- private function errorHandler(e:IOErrorEvent):void
- {
- sound.removeEventListener(IOErrorEvent.IO_ERROR,errorHandler);
- sound = null;
- }
- }
- }
热门文章推荐
- 纯HLS(m3u8)跨平台技术(HLSPlayer,m3u8Player跨平台多终端)
- DiscuzX3.2酷播视频插件(dz论坛自定义视频插件带广告
- [微信视频]实现网站中的视频在微信平台上正常播放(超多组图)
- [rtsp]海康威视监控摄像头实现web端无插件监控实拍效果
- 很酷,酷播wordpress视频插件(支持PC/安卓/苹果跨平台播放)
- [组图]微信视频技术:支持微信视频直播和视频点播
- [AS3]as3.0的rtmp流媒体播放器写法源代码示例
- 一步一步教你制作FLV网页视频播放器
请稍候...