[FMS]AS3.0基于FMS写的录音机代码示例(2)
核心播放 packagecom.DNight { importadobe.utils.CustomActions; importcom.DNight.events.PlayEvent; importflash.events.EventDispatcher; importflash.media.Video; importflash.net.NetConnection; importflas
核心播放
- package com.DNight
- {
- import adobe.utils.CustomActions;
- import com.DNight.events.PlayEvent;
- import flash.events.EventDispatcher;
- import flash.media.Video;
- import flash.net.NetConnection;
- import flash.net.NetStream;
- import flash.events.NetStatusEvent;
- import flash.media.SoundMixer
- /**
- * ...
- * @author DN
- */
- public class Player extends EventDispatcher
- {
- private var _path:String
- private var _video:Video;
- private var _netConnection:NetConnection;
- private var _netStream:NetStream;
- private var _duration:Number;
- private var _time:Number = 0;
- public function get duration() {
- return _duration
- }
- public function get stream() {
- return _netStream
- }
- public function Player(newPath)
- {
- _path = newPath;
- _video = new Video();
- _netConnection = new NetConnection();
- _netConnection.connect(Recorder.FMSSTR);
- _netConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandle);
- }
- private function netStatusHandle(eve:NetStatusEvent) {
- switch(eve.info.code) {
- case "NetConnection.Connect.Success":
- _netStream = new NetStream(_netConnection);
- _netStream.bufferTime = 3;
- var client:Object = new Object();
- client.onMetaData = onMetaData;
- client.onPlayStatus = onPlayStatus;
- _netStream.client = client;
- break
- }
- }
- private function onMetaData(data:Object) {
- _duration = data.duration;
- var event:PlayEvent = new PlayEvent(PlayEvent.GET_DUREATON);
- dispatchEvent(event);
- //极酷cuplayer提示:trace("音频长度"+_duration);
- }
- private function onPlayStatus(data:Object) {
- switch(data.code) {
- case "NetStream.Play.Complete":
- var event:PlayEvent = new PlayEvent(PlayEvent.PLAY_END);
- dispatchEvent(event);
- _time = 0;
- break
- }
- }
- public function play() {
- if (_time == 0) {
- _netStream.play(_path);
- }else {
- _netStream.resume();
- }
- }
- public function pause() {
- _time = _netStream.time;
- _netStream.pause();
- }
- public function stop() {
- trace("停止音乐");
- _netStream.close();
- SoundMixer.stopAll();
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...