NetStream.play + video.attachNetStream不会显示任何视频

发布于 2024-12-21 06:31:33 字数 1486 浏览 2 评论 0原文

我是 Flash 编程新手。我想做的就是将本地网络摄像头传输到我的 red5 服务器并接收另一个视频中的数据。

因此,我编写了以下代码:

    NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
    client_nc = new NetConnection();

    client_nc.objectEncoding = flash.net.ObjectEncoding.AMF0;

    client_nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
    client_nc.connect("rtmp://localhost/myApp/");

    function netStatusHandler(e:NetStatusEvent):void
    {
        var code:String = e.info.code;
            //log.info("code = " + code);
        if (code == "NetConnection.Connect.Success")
        {
            cam_ns = new NetStream(client_nc);

            cam_ns.attachCamera(camera);
            cam_ns.attachAudio(mic);

            cam_ns.publish("user_2", "live");
            in_ns2 = new NetStream(client_nc);

            in_ns2.play("user_2");

            video2 = new Video(640, 480);
            video2.attachNetStream(in_ns2);
            //in_ns2.play("rtmp://localhost/myApp/user_2");
            //in_ns2.play("user_2");
            video2.x = 200;
            video2.y = 10;
            video2.width = 100; 
            video2.height = 100;
            addChild(video2);

        }
        else
        {
            trace(code);
        }
    }

我在 1 个 NetConnections 上使用 2 个 NetStream,然后在第一个 NetConnections 上连接一个摄像头+麦克风。 之后,我播放此 NetStream 并尝试将此播放附加到第二个 Netstream 上并在新视频中播放。然而,这不起作用。

我对 as3 使用 flashdevelop,对 red5 服务器使用 eclipse。谁能帮助我吗?

I am new to Flash programming. All I wanted to do is stream my local webcam to my red5 server and receive the data in another video.

Therefore I wrote the following code:

    NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
    client_nc = new NetConnection();

    client_nc.objectEncoding = flash.net.ObjectEncoding.AMF0;

    client_nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
    client_nc.connect("rtmp://localhost/myApp/");

    function netStatusHandler(e:NetStatusEvent):void
    {
        var code:String = e.info.code;
            //log.info("code = " + code);
        if (code == "NetConnection.Connect.Success")
        {
            cam_ns = new NetStream(client_nc);

            cam_ns.attachCamera(camera);
            cam_ns.attachAudio(mic);

            cam_ns.publish("user_2", "live");
            in_ns2 = new NetStream(client_nc);

            in_ns2.play("user_2");

            video2 = new Video(640, 480);
            video2.attachNetStream(in_ns2);
            //in_ns2.play("rtmp://localhost/myApp/user_2");
            //in_ns2.play("user_2");
            video2.x = 200;
            video2.y = 10;
            video2.width = 100; 
            video2.height = 100;
            addChild(video2);

        }
        else
        {
            trace(code);
        }
    }

I use 2 NetStreams on 1 NetConnections and then attach a cam+mic on the first.
After that I play this NetStream and try to attach this playback on the 2nd Netstream and play it in a new Video. However, this doesnt work.

I use flashdevelop for as3 and eclipse for the red5 server. Can anyone help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南汐寒笙箫 2024-12-28 06:31:33

对我来说,它的工作方式如下:

    private function viewStream():void {            
        var stream:NetStream = new NetStream(nc);
        stream.client = new NetStreamClient();
        stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
        stream.play( streamName.text);          
        var video:Video = new Video();
        video.attachNetStream(stream);
        uic.addChild(video);    
    }               

    private function asyncErrorHandler(event:AsyncErrorEvent):void {
        trace(event.text);
    }

其中 nc 是我的单个全局 NetConnection,streamName 是 an

<mx:TextInput id="streamName" text="test"/>

,uic 是一个 UIComponent,

<mx:UIComponent id="uic" width="300" height="250"/>

我从按钮调用 viewStream 方法

<mx:Button label="view Stream" click="viewStream()"/>

,我也遇到了 VideoDisplay 问题。所以我用 UIComponent 做了,效果很好。
也许您遇到问题是因为您尝试在发布后直接 ns.play 。我认为您应该尝试使用按钮并在开始发布后稍等片刻。

for me it worked like this:

    private function viewStream():void {            
        var stream:NetStream = new NetStream(nc);
        stream.client = new NetStreamClient();
        stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
        stream.play( streamName.text);          
        var video:Video = new Video();
        video.attachNetStream(stream);
        uic.addChild(video);    
    }               

    private function asyncErrorHandler(event:AsyncErrorEvent):void {
        trace(event.text);
    }

where nc is my single global NetConnection and streamName is an

<mx:TextInput id="streamName" text="test"/>

and uic is an UIComponent

<mx:UIComponent id="uic" width="300" height="250"/>

i called viewStream method from a button

<mx:Button label="view Stream" click="viewStream()"/>

I had problems with VideoDisplay, too. So I did it with UIComponent and it works well.
Maybe you got problems because you try to ns.play directly after publish. I think you should try it with a button and wait a second after starting the publish.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文