Actionscript 3.0应用程序:netstream.play后,视频在Flash播放器中不可见

时间:2014-04-11 13:35:41

标签: actionscript-3 flash flex video rtmp

我已经安装了adobe flex sdk 4.6并在MXML文件中编码了一个非常基本的功能:使用RTMP从Adobe媒体服务器播放FLV视频。但是当我在flashplayerdebugger中运行已编译的swf文件时,它不会显示视频 - 它会立即触发NetStream.Play.Start和NetStream.Play.Reset。但是没有显示视频。

这是代码 - play.mxml:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx" width="640" height="480">

    <s:layout>
        <s:BasicLayout />
    </s:layout>

    <s:Label id="textLbl" horizontalCenter="0" verticalCenter="0" />
<s:Button id="connectBtn" label="Connect" click="connectHandler();"/>
<fx:Script>
    import flash.net.NetConnection; 
    import flash.events.NetStatusEvent; 
    import flash.events.MouseEvent; 
    import mx.core.UIComponent;
    import mx.controls.Alert;

    public var nc:NetConnection;
    public var vid:Video ;
    public var container:UIComponent;

    public function connectHandler():void {
                nc = new NetConnection(); 
        nc.client = { onBWDone: function():void{} };
                nc.connect("rtmp://localhost:1935/vod");  
        nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);


        container = new UIComponent();
        addElement( container );

        vid = new Video(); 
        vid.width= 600;
        vid.height = 600;
        container.addChild(vid);
    }

    public function playVideo():void {
        var ns:NetStream = new NetStream(nc); 
        ns.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);
        ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); 
        vid.attachNetStream(ns);
        ns.play("sample.flv"); 
        connectBtn.label = "Playing";

    }       

public function netStatusHandler(event:NetStatusEvent):void 
{ 
    // handle netStatus events, described later 
    switch (event.info.code) {
        case "NetConnection.Connect.Success":
        connectBtn.label = "Disconnect";
        playVideo();
        break;
    default:
        Alert.show(event.toString() + "//" + event.info.code +
            "//" + event.info.level );
        break;
    }
} 

public function asyncErrorHandler(event:AsyncErrorEvent):void 
{ 
    // ignore error 
        Alert.show(event.toString() + "//" + event.error.message + 
            "//" + event.error.name);
}

</fx:Script>
</s:Application>

编译时我只做:mxmlc play.mxml

用于运行:flashplayerdebugger play.swf

我在这里缺少什么。

0 个答案:

没有答案