这些天在研究flashcom的mp3 库.flashcom,我比较陌生.只在大四上的时候,花了一天半的时间搞过一个视频录制的.以前在工作室没把音箱带过去, 省得吵,结果一年多没有听到机器发声.对音频这方面知道的甚少, 快成盲了 . 在这里非常感谢云开的无私帮助.
看macromedia媒体组件的流媒体包,觉得还是收获蛮大,以下分析的是基于RTMP协议的Netconnection的一个子类. 在mx.controls.streamingmedia包中.
//**************************************************************************** //Copyright (C) 2003 Macromedia, Inc. All Rights Reserved. //The following is Sample Code and is subject to all restrictions on //such code as contained in the End User License Agreement accompanying //this product. //**************************************************************************** import mx.controls.streamingmedia.RTMPPlayer; import mx.controls.streamingmedia.Tracer;//做调试的trace /** * A subclass of NetConnection that is tailored to work with the RTMPPlayer * class. * 一个专门为RTMPPlayer定制的NetConnection类的子类 * @author Stephen Cheng */ class mx.controls.streamingmedia.RTMPConnection extends NetConnection { /** Flag to indicate whether a thread is already in connect(). Only one thread * at a time should be in this function. * 标记是否已有一个线程在连接,同一时刻只能有一个线程连接 */ static var _connectFlag:Boolean; /** Array of queued RTMPPlayers, awaiting their turn to call connect(). */ //RTMPPlayers队列(实际上是RTMPConnection的数组),等待连接 static var _connectorQueue:Array = new Array(); private var _targetURI:String;//目标资源地点 private var _streamName:String;//流的名称 private var _player:RTMPPlayer;//运行的RTMPPlayer实例 //构造函数,参数为一个RTMPPlayer的实例 public function RTMPConnection(player:RTMPPlayer) { _player = player; } // 当元数据从flash communication server到来时 // 播放器从服务器发来的信息设置总播放时间 public function onMetaData(info) { _player.setTotalTime(info.duration); } /* Only one thread can be in this function at a time. * 同一时刻只有一个线程可以使用这个连接函数 */ public function connect(targetURI:String, streamName:String):Void { //如果已经存在一个线程正在连接 //则把此连接放入到等待队列中 //并返回 if (_connectFlag == true) { pushConnection(targetURI, streamName); return; } //如果不存在则把先把连接标记设为true //然后再连接目标 _connectFlag = true; super.connect(targetURI, streamName); //当前连接执行完后从队列 //弹出最近压入的RTMPConnection实例,并执行连接 popConnection(); } private function pushConnection(targetURI:String, streamName:String):Void { //压入队列 _targetURI = targetURI; _streamName = streamName; //queue the connection attempt and retry later _connectorQueue.push(this); } //弹出最近压入的RTMPConnection实例,并执行连接 private function popConnection():Void { _connectFlag = false; if ( _connectorQueue.length != 0) { var poppedConnection:RTMPConnection = RTMPConnection(_connectorQueue.pop()); poppedConnection.connect(poppedConnection._targetURI, poppedConnection._streamName); } } }
当中的连接队列, 与其就是个队列不如说是个堆栈.这样使得连接变成先进后出了,这可不太好. 假如pop出来的RTMPConntion连接时间过长,此时又有新的连接.
那在栈底的岂不是永远天日.而且连接也不分个等级,有可能因为都是为Player服务的,所以干脆不分~~~~~ 好faint.