Can't record audio...
I don't seem to be able to record audio with my microphone to flash media server. Every time I try a 1kb flv file is made, but it is empty when I try to play it back, and basically doesn't work. I didn't install apache server when I installed media server because I already have it installed. Could this make a difference? My code is below. Any ideas?
package {
import flash.display.MovieClip;
import flash.net.NetConnection;
import flash.events.NetStatusEvent;
import flash.events.MouseEvent;
import flash.net.*;
import flash.media.Microphone;
import flash.system.*;
public class HelloServer extends MovieClip {
private var nc:NetConnection;
var myNS:NetStream;
var mic:Microphone;
/*
* Constructor.
*/
public function HelloServer() {
// register listeners for mouse clicks on the two buttons
connectBtn.addEventListener(MouseEvent.CLICK, connectHandler);
closeBtn.addEventListener(MouseEvent.CLICK, closeHandler);
}
//Once Connected
public function connected():void{
myNS = new NetStream(nc);
myNS.attachAudio(mic);
myNS.publish("alex" + Math.random(), "record");
}
/*
* Connect to the server.
*/
public function connectHandler(event:MouseEvent):void {
mic = Microphone.getMicrophone();
//Security.showSettings(SecurityPanel.PRIVACY);
mic.rate = 22;
mic.setUseEchoSuppression(true);
trace("Okay, let's connect now");
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nc.connect("rtmp://localhost/HelloServer");
}
/*
* Disconnect from the server.
*/
public function closeHandler(event:MouseEvent):void {
trace("Now we're disconnecting");
myNS.close();
nc.close();
}
/*
* Handle events relating to the server connection.
*/
public function netStatusHandler(event:NetStatusEvent):void {
trace("connected is: " + nc.connected);
trace("event.info.level: " + event.info.level);
trace("event.info.code: " + event.info.code);
switch (event.info.code)
{
case "NetConnection.Connect.Success":
trace("Congratulations! you're connected" + "\n");
connected();
break;
case "NetConnection.Connect.Rejected":
trace ("Oops! the connection was rejected" + "\n");
break;
case "NetConnection.Connect.Closed":
trace("Thanks! the connection has been closed" + "\n");
break;
}
}
}
}
