1 Reply Latest reply on May 27, 2011 10:58 AM by Michael Thornburgh

    Need help to display my webcam using p2p connection

    MaaaaT

      Hi,

       

      I try to publish and play my own webcam but i can't. Could you please help me ?

      This is my code :

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"   
                      layout="absolute" creationComplete="init()">
          <mx:Script>

              import mx.controls.Label;
              import mx.controls.Alert;
              import mx.core.UIComponent;
              import mx.controls.Button;
              import flash.net.NetConnection;
             
             
             
              private var nc:NetConnection;
             
              private function init():void {
                 
                 
                  // Connect to cirrus
                  nc = new NetConnection();
                  nc.client = this;
                  nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
                  nc.connect("rtmfp://p2p.rtmfp.net/******************************************************* *******");
                 
              }
             
             
              private function onNetStatus(event:NetStatusEvent):void{
                  Alert.show(event.info.code );         
                  if (event.info.code == "NetConnection.Connect.Success") {
                      var vContainer:UIComponent = new UIComponent();
                     
                      // Local webcam copy
                      var label1:Label = new Label();
                      label1.x = 0;
                      label1.y= 0;
                      label1.text = "Your webcam if you have any:";
                      addChild(label1);
                     
                      var cam:Camera = new Camera();
                      cam = Camera.getCamera();
                      var localvid:Video = new Video();
                      localvid.x = 10;
                      localvid.y = 20;
                      localvid.attachCamera(cam);
                     
                      vContainer.addChild(localvid);
                     
                      addChild(vContainer);
                     
                      // Publish
                      var ns:NetStream = new NetStream(nc);
                      ns.attachCamera(cam);
                      ns.publish("testlive");
                  }
                 
                  // Re-play from FMS
                  label1 = new Label();
                  label1.x = 400;
                  label1.y= 0;
                  label1.text = "Streamed video";
                  addChild(label1);
                 
                  var nsPlayer:NetStream = new NetStream(nc);
                  nsPlayer.play("testlive");
                  var vid:Video = new Video();
                  vid.x = 400;
                  vid.y = 20;
                  vid.attachNetStream(nsPlayer);
                  //vid.smoothing = true;
                 
                  vContainer.addChild(vid);
                  addChild(vContainer);
              } 
             
          </mx:Script>      
      </mx:Application>

       

       

      Sorry for my bad english.

      Thank you,

      Mathieu

        • 1. Re: Need help to display my webcam using p2p connection
          Michael Thornburgh Adobe Employee

          you are trying to publish your camera client-server to the Cirrus service, and then subscribe to it. Cirrus is not FMS; it does not provide client-server streaming, shared objects, server side scripts, etc. like FMS does.  Cirrus's only function is to facilitate P2P communication.

           

          in general, RTMFP P2P functions don't support "loopback" in the same NetConnection.  so, for example, you can't publish a 1:1 NetStream and then try to do a P2P subscribe to your own peer ID on the same NetConnection.  in other words, the following won't work:

           

             var nc1:NetConnection = new NetConnection;

             nc1.connect("rtmfp://p2p.rtmfp.net", "my-devkey");

           

             var pubNS:NetStream = new NetStream(nc1, NetStream.DIRECT_CONNECTIONS);

             ...attach camera/microphone

             pubNS.publish("livestream");

           

             var subNS:NetStream = new NetStream(nc1, nc1.nearID); // this won't do anything

             ...attach to display object

             subNS.play("livestream");

           

          however, you could make a second NetConnection, which would have a different peer ID, and do P2P between the two of them in the same SWF:

           

             var nc2:NetConnection = new NetConnection;

             nc2.connect("rtmfp://p2p.rtmfp.net", "my-devkey");

           

             var subNS:NetStream = new NetStream(nc2, nc1.nearID); // this will make a P2P connection to NetConnection nc1

             ...

             subNS.play("livestream");

           

          if you just want to display your camera's captured video in a display object, you can simply attach the camera to a display object like an mx:VideoDisplay; you don't need to send it over the network.

          1 person found this helpful