Tuesday, March 23, 2010

FLEX 2.0 and Flash Media Server 2.0...

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.





%26lt;?xml version=''1.0'' encoding=''utf-8''?%26gt;



%26lt;mx:Application xmlns:mx=''
http://www.adobe.com/2006/mxml''


applicationComplete=''startup()''%26gt;



%26lt;mx:Script%26gt;

%26lt;![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);

}



]]%26gt;

%26lt;/mx:Script%26gt;



%26lt;mx:Canvas xmlns:mx=''
http://www.adobe.com/2006/mxml''
width=''400''

height=''300''%26gt;

%26lt;mx:HBox left=''19'' right=''0'' height=''100'' top=''30''%26gt;

%26lt;mx:Label text=''Label'' id=''lblMessage'' width=''150''/%26gt;

%26lt;mx:Button label=''Start'' click=''toggle()'' id=''submit''/%26gt;

%26lt;/mx:HBox%26gt;





%26lt;/mx:Canvas%26gt;





%26lt;/mx:Application%26gt;

No comments:

Post a Comment