0

我只是想制作一个简单的 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 流......

为什么会这样?我做错了什么?有任何想法吗?

4

1 回答 1

1

ns.addEventListener(NetStatusEvent.NET_STATUS, netStatus); 您可以将此侦听器添加到 NetConnection 和 NetStream 对象,这样您将看到您的流状态是什么,我猜您没有正确访问流的名称,但无法确定。

使用它来检查您的流是否可用:http ://www.osmf.org/configurator/fmp/

于 2012-07-26T18:21:31.750 回答