流式视频播放器/将视频(不是摄像头)附加到动作脚本3中的NetStream

时间:2013-09-20 08:37:21

标签: actionscript-3 flex flex4.6 netstream flash-media-server

我是动作脚本的新手,基本上我正在尝试流式播放视频播放器,但我们无法在as3中使用attachVideo,那么我可以在下面的代码中使用什么代替attachVideo?我正在使用flash builder / flex 4.6。如果您可以为流式视频播放器建议链接/教程,那将是非常有帮助的。谢谢!

   private function initOutStream():void
            {     /* streamOut is NetStream to adobe cirrus , 
                    conn is making connection to adobe cirrus */    
          trace("initOutStream");
          streamOut = new NetStream(conn,NetStream.DIRECT_CONNECTIONS);
          streamOut.addEventListener(NetStatusEvent.NET_STATUS,streamStatus);
          streamOut.publish("media");

                  // mp4 file from local machine

                  nc = new NetConnection();                           
                  nc.connect(null); 
                  ns = new NetStream(nc);
                  ns.play("t.mp4");
                  ns.client = this;

                  var vid:Video = new Video;
                  vid.attachNetStream(ns);

          // streaming vid to media server

                  streamOut.attachVideo(vid);

         var streamOutClient:Object = new Object(); 
         streamOutClient.onPeerConnect = function(farStream:NetStream):Boolean
                   {   
                     return true;         
                   }       
              }

错误: 1061:通过静态类型

的引用调用可能未定义的方法attachVideo

1 个答案:

答案 0 :(得分:0)

这是我最近为商业工作写的代码。我希望它有所帮助...

var vid:Video = new Video();
vid.width = 640; vid.height = 480;
addChild(vid);

var cnn:NetConnection = new NetConnection();
cnn.connect(null);

var ns:NetStream = new NetStream(cnn);

ns.play("t.mp4");

vid.attachNetStream(ns);

ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, error);
ns.addEventListener(NetStatusEvent.NET_STATUS, streamStatus);

function streamStatus(e:NetStatusEvent){
    //trace(e.info.code);
    if(e.info.code == "NetStream.Play.Stop"){

    }
}

function error(e){

}