Skip to main content
December 3, 2011
Question

Client-side NetStream webcam publishing to FMS 4.5 not working

  • December 3, 2011
  • 1 reply
  • 1211 views

I'm trying to create a simple application that streams the webcam to FMS 4.5 (running on a Windows 7 machine), and then displays the published stream locally. Here's my code:

import flash.net.NetStream;

import flash.media.Video;

import fl.video.FLVPlayback;

import flash.events.NetStatusEvent;

var cam = Camera.getCamera();

var mic = Microphone.getMicrophone();

var video = new Video();

video.y = 480;

addChild(video);

video.attachCamera(cam);

var nc = new NetConnection();

nc.client = this;

nc.connect("rtmp://localhost/live");

nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

function netStatusHandler(event:NetStatusEvent):void {

          if (event.info.code == "NetConnection.Connect.Success") {

                    trace("NetConnection successful");

              var ns = new NetStream(nc);

                    ns.addEventListener(NetStatusEvent.NET_STATUS, publishHandler);

                    ns.attachCamera(cam);

                    ns.attachAudio(mic);

                    ns.bufferTime = 0;

        ns.publish("test1", "live");

 

 

          }

}

function publishHandler(event:NetStatusEvent):void {

          trace(event.info.code);

          if(event.info.code == "NetStream.Publish.Start") {

                    vplayer.source = "rtmp://localhost/live/test1";

          }

}

All traces in the event handlers show the NetConnection connecting successfully, and the netstream publishing successfully. However, I get no video output from this. I've confirmed this using the sample video player in FMS 4.5 as well. There is also a weird traffic pattern reported in the FMS Admin console. There is some traffic (~4K) when the NetStream first publishes, but after that there is no activity. Can anyone please help?

This topic has been closed for replies.

1 reply

December 3, 2011

Looks like a scope problem. You're defining the netstream variable in a method, so the netstream's scope is the method. So, once the method is done executingm the netstream is eligible for garbage collection.

Try defining the netstream at the top of the class, rather than inside a member method.