我只想创建一个简单的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流......
为什么会这样?我做错了什么?有什么想法吗?
答案 0 :(得分:1)
ns.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
你可以将这个监听器添加到NetConnection和NetStream对象中,你会看到你的流状态是什么,我猜你没有正确访问流的名称,但无法确定。
使用此功能检查您的信息流是否可用:http://www.osmf.org/configurator/fmp/