本文介绍了NetStream.publish网络摄像头,以柔性制造系统在独立播放器的工作,而不是在浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想发布一个网络摄像头的视频到Flash媒体服务器2。我的code是工作在Flash独立播放器(10.0和10.2测试),而不是在浏览器插件(10.2进行测试,无论是在IE浏览器和Opera。我的FMS的连接工作正常,但发布,没有任何反应后,我从来没有得到NetStream.Publish.Start事件。在服务器上,我可以看到流选项卡,在管理控制台的连接,甚至流。但我无法连接到该STREA。

任何人的想法可能是什么问题呢?

 将NetConnection.defaultObjectEncoding =为ObjectEncoding.AMF0; //需要得到正确的连接FMS2

私有函数的netStatusHandler(事件:将NetStatusEvent):无效{
        output.appendText(\ N+ event.info code);
        开关(event.info。code){
            案值为NetConnection.Connect.Success:
                output.text =(连接成功,流摄像头......);
                connectCamera();
                打破;
            案NetConnection.Connect.Failed:

                打破;
            案NetStream.Play.StreamNotFound:
                打破;

            案NetStream.Publish.Start:
                output.appendText(\ nPublishing视频!);
                打破;

        }
    }

    私有函数connectCamera(EV:事件= NULL):无效{
        VAR流:NetStream的=新的NetStream(连接);
        stream.addEventListener(NetStatusEvent.NET_STATUS,的netStatusHandler);
        stream.attachCamera(照相机);
        videoURL = createGUID();
        stream.publish(videoURL,活);
        output.text =发布流......;
    }
 

解决方案

好吧,我发现我的问题是在这里什么:我宣布提及的的的connectCamera函数内部变量:

 私有函数connectCamera(EV:事件= NULL):无效{
    VAR流:NetStream的=新的NetStream(连接);
}
 

那么的的仅是函数的范围内声明。这似乎不是要在独立播放器中的问题,但它是在浏览器插件。该浏览器插件似乎做垃圾收集更加thourough工作,垃圾回收我流功能执行后。所以我要做的就是声明的的功能范围之外的变量,里面的类范围。

  VAR流:NetStream的;
私有函数connectCamera(EV:事件= NULL):无效{
    流=新的NetStream(连接);
}
 

您应该始终声明,你以后作为一个字段需要在你的类的东西,而不是内部的功能。你永远不知道什么时候GC会清理的东西。

I am trying to publish the video of a webcam to a Flash Media Server 2.My code is working in the Flash standalone player (tested with 10.0 and 10.2), but not in the browser plugin (tested with 10.2, both in IE and Opera.The connection to my FMS is working successfully, but after the publish, nothing happens, I never get the NetStream.Publish.Start Event. On the server I can see the connection in the management console, even the stream in the streams tab. But I cannot connect to that strea.

Anybody an idea what could be going wrong?

NetConnection.defaultObjectEncoding = ObjectEncoding.AMF0; // needed to get correct connection to FMS2

private function netStatusHandler(event:NetStatusEvent):void {
        output.appendText("\n" + event.info.code);
        switch (event.info.code) {
            case "NetConnection.Connect.Success":
                output.text = ("Connection successful, streaming camera...");
                connectCamera();
                break;
            case "NetConnection.Connect.Failed":

                break;
            case "NetStream.Play.StreamNotFound":
                break;

            case "NetStream.Publish.Start":
                output.appendText("\nPublishing video!");
                break;

        }
    }

    private function connectCamera(ev:Event = null):void {
        var stream:NetStream = new NetStream(connection);
        stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        stream.attachCamera(camera);
        videoURL = createGUID();
        stream.publish(videoURL, "live");
        output.text = "publish stream...";
    }
解决方案

Ok, I found what my problem is here:I declare the reference to the stream variable inside the connectCamera function:

private function connectCamera(ev:Event = null):void {
    var stream:NetStream = new NetStream(connection);
}

So stream is only declared inside the scope of that function.This doesn't seem to be a problem in the standalone player, but it is in the browser plugin. The browser plugin seems to do a much more thourough job on the garbage collector, garbage collecting my stream after the function has executed.So what I have to do is declare the stream variable outside of the function scope, inside the class scope.

var stream:NetStream;
private function connectCamera(ev:Event = null):void {
    stream = new NetStream(connection);
}

You should always declare stuff that you need later as a field on your class, and not inside a function. You just never know when GC might clean up that stuff.

这篇关于NetStream.publish网络摄像头,以柔性制造系统在独立播放器的工作,而不是在浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 21:57