我只是想制作一个简单的 Flash Player,它可以使用 Flash ActionScript 播放 rtmp 流......
这是我的代码:
import flash.display.Sprite;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Video;
import flash.events.*;
var nc : NetConnection;
var ns : NetStream;
var vid : Video;
var monitorBufferLengthEverySecond:uint;
var counter:uint;
vid=new Video();
vid.width=640;
vid.height=480;
trace("Create ... NetConnection");
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, netSecurityError);
nc.connect("rtmp://x.x.x.x/live");
function netStatus(event:NetStatusEvent):void
{
trace("Net Satus: "+ event.info.code);
if(event.info.code == "NetConnection.Connect.Success")
{
trace("Net Satus is OK");
trace("Creating NetStream");
ns = new NetStream(nc);
var infoClient:Object = new Object();
infoClient.onMetaData = function oMD():void {};
infoClient.onCuePoint = function oCP():void {};
ns.client = infoClient;
ns.play("IPCamera.stream");
vid.attachNetStream(ns);
monitorBufferLengthEverySecond = setInterval(monPlayback, 1000);
}
}
function netSecurityError(event:SecurityErrorEvent):void
{
trace("Security error: " + event);
}
function monPlayback():void
{
// Print current buffer length
trace((++counter)+ " Buffer length: " + ns.bufferLength);
}
连接成功*但是*当我尝试检查缓冲区时,我总是得到“0”长度......而且我看不到 RTMP 流......
为什么会这样?我做错了什么?有任何想法吗?