来自crtmp-server的as3流

时间:2016-07-13 15:07:16

标签: actionscript-3 video

如果我在Adobe Flash中使用媒体播放组件,则crtmp-server上的视频流正常运行。

如果我试图在不使用该组件的情况下自行完成此操作,我会遇到一些错误,不幸的是没有太多支持在没有媒体播放组件的情况下解释as3上的流媒体。

我有以下代码



package
{
	import flash.display.MovieClip;
	import flash.media.Video;
	import flash.net.NetConnection;
	import flash.net.NetStream;
	
	
	/**
	 * ...
	 * @author Siam Modi
	 */
	public class Main extends MovieClip
	{
		
		public function Main()
		{
			
			var nc:NetConnection = new NetConnection();
			nc.connect("rtmp://213.136.73.230/maya");
			var vid:Video = new Video();
			addChild(vid);
			var ns:NetStream = new NetStream(nc);
			
			vid.attachNetStream(ns);
			ns.play("atlas.mp4");
		}
	
	}

}




有什么想法吗?请求帮助

1 个答案:

答案 0 :(得分:1)

只有在使用NetStream NetConnection触发NetStatusEvent后,您才能将NetConnection.Connect.Succesinfo.code个实例相关联。 要举办此活动,您需要致电nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler)
在打电话之前 nc.connect("rtmp://213.136.73.230/maya");
并附上NetStream / Video

    private function netStatusHandler(event:NetStatusEvent):void {
        switch (event.info.code) {
            case "NetConnection.Connect.Success":
                var ns:NetStream = new NetStream(nc);   
                vid.attachNetStream(ns);
                ns.play("atlas.mp4");

            break;
            case "NetStream.Play.StreamNotFound":
                trace("Stream not found: " + videoURL);
            break;
        }
    }

here is an example from the reference