开发者

Settings for RTMP and AS 3.0

开发者 https://www.devze.com 2022-12-25 09:01 出处:网络
Is there any extra code need for using rtmp with AS3. I have the code like this. Is that enough for rtmp or any other code needed?

Is there any extra code need for using rtmp with AS3.

I have the code like this. Is that enough for rtmp or any other code needed?

var strSource:String = "rtmp://myserver.com/file.flv";
var nc开发者_开发问答Connection = new NetConnection();
var nsStream = new NetStream(ncConnection);
nsStream.play(strSource);


Playing RTMP streams needs to be done differently that progressive ones.

First you need to connect to the application, usually this is the base path but can sometimes be some folder up in case the RTMP server proposes different services.

You then need to listen to the NetConnection.Connect.Success event dispatched by the NetConnection event.

Once the NetConnection is connected you can create a NetStream upon it and thereafter play the stream.

Note that the argument passed to the play command should only be the name of the stream and not the full path. Normally you also need to remove the extension (depends on server and service). For H264 streams you may also need to prefix the stream id with "mp4:".

Example :

// rtmp://myserver.com/service/myVideo.flv

var service:String = "rtmp://myserver.com/service/";
var streamID:String = "myVideo"; // or mp4:myVideo for H264

var netConnection:NetConnection;
var netStream:NetStream;

netConnection = new NetConnection();
netConnection.client = {onBWDone:onNetConnectionBWDone}; 
netConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); 
netConnection.connect(service); 

// NetConnection status handlers

function netStatusHandler( event:NetStatusEvent ):void
{
    if(event.info.code == NetConnection.Connect.Success)
    {
        netStream = new NetStream(netConnection);
        netStream.client = {onMetaData:onMetaData, onPlayStatus :onPlayStatus};
        netStream.play(streamID);
    }
}

function onNetConnectionBWDone():void{}

// NetStream Status handlers

function onMetaData(o:Object):void{}
function onPlayStatus(o:Object):void{}
0

精彩评论

暂无评论...
验证码 换一张
取 消