2

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...";
    }
Malyngo
  • 863
  • 7
  • 18
  • do you receive any NetStream status events? – www0z0k Mar 24 '11 at 17:46
  • Are you deploying your application on some web-server before testing it or are you running it directly from the disk? – bmleite Mar 24 '11 at 21:58
  • I have tried it from local (opening the swf embedded in a html page directly from the filesystem) and also put it on a webserver. From the same webserver I was able to connect to the media server just fine in previous projects, but this is the first time I am using as3 to connect to the FMS2. When trying from browser, directly from disk or from a webserver, I don't get any NetStream status events, but I get them as expected in the standalone player. – Malyngo Mar 25 '11 at 08:02
  • @Malyngo , I am trying to create a webcam video publisher swf in flash cs6 which will output a livestream url like in red5 publisher except where i can better control the quality. Do you handle the codec and fps etc within flash or do you use ffmpeg? – cea Mar 30 '14 at 07:10
  • @cea, I think you should maybe start another question. When streaming to the Flash Media server from the webcam, this is just the Flash player streaming to the Media Server, no other things involved (I wouldn't even know how). For the streaming quality, there are a few params you can set on your webcam, not the least is to make sure you are using the h264 codec for encoding the webcam stream (This is available since FP11, I think). This can all be done with Flash alone. – Malyngo Mar 31 '14 at 08:15
  • Yes codec is all important - i stream to red5 because not using on desktop. I can't ask in here because i have been perm banned from the forum because they don't think my questions are of enough quality. – cea Mar 31 '14 at 08:42

1 Answers1

1

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.

Malyngo
  • 863
  • 7
  • 18