0 Replies Latest reply on May 11, 2007 1:41 PM by PallayyaBatchu

    FLEX 2.0 and Flash Media Server 2.0 Unable to stream from client to server

    PallayyaBatchu
      Hi All,

      I have been trying to put together a quick demo to stream and record audio from Client to Server. I get this error when trying to connect to FMS.

      ArgumentError: Error #2126: NetConnection object must be connected.
      at flash.net::NetStream/flash.net:NetStream::construct()
      at flash.net::NetStream$iinit()
      at Audio/toggle()
      at Audio/__submit_click()

      my Program fails at this line - ns = new NetStream(nc);


      Your help is greatly appreciated. Here is the MXML file Audio.mxml

      This file contains a simple start and stop button start and stop audio processing.

      This page is served from Apache Tomcat on host : demoserver1 and port 8080

      Flash media server is also installed on the same host demoserver1.

      I did not do any additional config at FMS except creating an application called "DemoApp". All other settings are defaults.


      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      applicationComplete="startup()">

      <mx:Script>
      <![CDATA[
      import flash.net.NetConnection;
      import flash.net.NetStream;

      public var started:Boolean = false;
      public var nc:NetConnection;
      public var ns:NetStream;
      public var mp:Microphone;

      public function startup():void{
      lblMessage.text="Stopped";
      }


      public function toggle():void{
      if (started==false){

      submit.label="Stop";
      started=true;
      lblMessage.text="Started";

      nc = new NetConnection();
      nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
      nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
      nc.objectEncoding = flash.net.ObjectEncoding.AMF0;

      nc.connect("rtmp://demoserver1/DemoApp");

      ns = new NetStream(nc);
      ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
      mp = Microphone.getMicrophone(0);
      ns.attachAudio(mp);
      ns.publish("sample1", "record");

      }
      else{
      started=false;
      submit.label="Start";
      lblMessage.text="Stopped";

      ns.close();
      nc.close();



      }
      }

      private function netStatusHandler(event:NetStatusEvent):void {
      switch (event.info.code) {
      case "NetConnection.Connect.Success":
      trace(" connection success : " );
      break;
      case "NetStream.Play.StreamNotFound":
      trace("Stream not found: " );
      break;
      }
      }

      private function
      securityErrorHandler(event:SecurityErrorEvent):void {
      trace("securityErrorHandler: " + event);
      }

      ]]>
      </mx:Script>

      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="400"
      height="300">
      <mx:HBox left="19" right="0" height="100" top="30">
      <mx:Label text="Label" id="lblMessage" width="150"/>
      <mx:Button label="Start" click="toggle()" id="submit"/>
      </mx:HBox>


      </mx:Canvas>


      </mx:Application>