2

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?

Bart
  • 19,692
  • 7
  • 68
  • 77
Wandang
  • 912
  • 2
  • 8
  • 37
  • Try to create one more Netconnection and use that connection for video play. you have to add that video object to VideoDisplay as a child.. – arulraj.net Sep 20 '12 at 09:29

1 Answers1

0

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.

steven
  • 4,868
  • 2
  • 28
  • 58