Skip to main content
May 24, 2011
Question

Help!!!

  • May 24, 2011
  • 2 replies
  • 2984 views

why does this code not work???

package
{
  import flash.display.Sprite;
  import flash.media.Camera;
  import flash.media.Microphone;
  import flash.media.Video;
  import flash.net.NetConnection;
  import flash.net.NetStream;
  import flash.net.ObjectEncoding;
  import flash.events.NetStatusEvent;

  public class MinCam extends Sprite
  {
        private var cam:Camera;
        private var mic:Microphone;
        private var vid1:Video;
        private var vid2:Video;
        private var nc:NetConnection;
        private var nsOut:NetStream;
        private var nsIn:NetStream;
        private var rtmpNow:String;
        private var msg:Boolean;

        public function MinCam ()
        {
             cam = Camera.getCamera();
             mic = Microphone.getMicrophone();

             //Camera Settings
             cam.setKeyFrameInterval (15);
             cam.setMode (240,180,15,false);
             cam.setMotionLevel (35,3000);
             cam.setQuality (40000 / 8,0);

             //Microphone Settings
             mic.gain = 85;
             mic.rate= 11;
             mic.setSilenceLevel (25,1000);
             mic.setUseEchoSuppression (true);

             //Video Setup
             vid1=new Video(cam.width,cam.height);
             vid2=new Video(cam.width,cam.height);
             addChild (vid1);
             vid1.x=10,vid1.y=20;
             addChild (vid2);
             vid2.x=vid1.width+15,vid2.y=20;

             //Attach local video and camera
             vid1.attachCamera (cam);

             //Connect
             nc = new NetConnection;
             nc.connect (rtmpNow);
             rtmpNow = "rtmp://192.168.0.11/vid3";
            
             nsOut = new NetStream(nc);
             nsIn = new NetStream(nc);
             //NetStream
             nsOut.attachAudio (mic);
             nsOut.attachCamera (cam);
             nsOut.publish ("camstream");
             vid2.attachNetStream (nsIn);
             nsIn.play ("camstream");
        }

       
  }
}

    This topic has been closed for replies.

    2 replies

    Inspiring
    May 24, 2011

    Ah never mind. Your doing zero event handling which is a requirement of streaming video.

    You need to listen for the NetConnection to connect to the media server before you attach the NetStream.

    Also this:


          nc.connect (rtmpNow);   
          rtmpNow = "rtmp://192.168.0.11/vid3";

    Should be:

         rtmpNow = "rtmp://192.168.0.11/vid3";

         nc.connect (rtmpNow);

    What ever server you're using. FMS/Wowza should have demos in them. Check them out to see whats going on.

    May 24, 2011

    I'm not sure what you mean by this "You need to listen for the NetConnection to connect to the media server before you attach the NetStream." or "What ever server you're using. FMS/Wowza should have demos in them. Check them out to see whats going on."

    also i changed the other suggestion you made and now the error is "ArgumentError: Error #2126: NetConnection object must be connected."

    before it was" Error #2044: Unhandled NetStatusEvent:. level=error, code=NetStream.Play.StreamNotFound"

    Edit: Also what do you suggest that i should do for error handling.

    Nikhil_Kalyan
    Participating Frequently
    May 24, 2011

    To explain the error you are getting : ArgumentError: Error #2126: NetConnection object must be connected."

    It is because the netstream object (which needs the netconnection object) is made even before the netconnection object is properly made. And hence the error is in the argument for the net stream. This is happening as your code is not waiting for the netconnection to be properly made first and then try for a netstream. You should be using the event handlers (as suggested in the replies above) to first wait and catch the netconnection success handler and then attempt to open a net stream.

    One quick example that i can find : http://injun.ru/flash10api/flash/net/NetStream.html#includeExamplesSummary

    Thank you !

    Inspiring
    May 24, 2011

    What's the error you're getting?