My first red5 flex video recorder

So this is a bit cooler than adding two numbers together....
Here's my very first bare-bones Flex / red5 video recorder, and a few lessons I learned in creating it.

1) Red5 handles NetSteam's .publish() methods automagically. In other words, your java application does not have to do anything except extend ApplicationAdapter to let you use it from Flex to record video. In fact, if you don't want to tinker with java/red5 at all, you can just use a demo application like oflaDemo as your NetConnection hookup. So if you have red5 running out of the box and do:

private function connect():void
{
nc = new NetConnection();
  nc.connect("rtmp://localhost/oflaDemo");
    nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
}

private function netStatusHandler(e:NetStatusEvent):void  {   
var code:String = e.info.code;   
Alert.show("code = " + code);  
if(code == "NetConnection.Connect.Success"){ 
        ns = new NetStream(nc);        //plus other stuff if you need.
}   
   else   {   
   trace(code);  
   } 
}

Bingo, you have a NetStream ready for the attachCamera() method. Once you attach your camera, all you need to do is call ns.publish("my title", 'record');, and red5 will automatically create the FLV for you and store it as "[my title].flv" in the streams/ directory of the red5 webapp you're connecting to. Surprisingly, it will even CREATE the streams directory if it doesn't exist. Fantastic, no???? Here's some sample code to publish the stream:

private function publishCam():void
{
try
{
//Alert.show('publishing');
        ns.attachCamera(camera);
        mic.rate = 44;
        ns.attachAudio(mic);
ns.publish("red5test", 'record');
}
catch(err:Error)
{
Alert.show( err.toString() );
}

}

So notice I am using the very same "myapp" application that I created in my last blog post. It provides NO SPECIAL hooks of anykind to let us record video. Everything not done in actionscript is handled by red5 automatically.

Whoa...Amazing, huh? What they say is true- red5 really makes it SIMPLE to make your own video recorders...

2) There is a bug with 64-bit flash on Ubuntu where it borks the camera if I try to access the Camera class from two flex apps simultaneously. I have to restart firefox for video to return to normal. I'm getting really sick of Adobe's lack of support for 64-bit linux (No FP 10 debug player?!?) ...I thought they were trying to court Linux developers...

3) If you're using the microphone to record with red5, make sure to set the rate to 44 so you don't have FLV codec problems. And use Microphone.getMicrophone() instead of Microphone.get() in AS3.

Holy wow, this is some powerful stuff red5 provides us Flex developers with. VERY powerful stuff...

AttachmentSize
myapp.tar_.gz147.23 KB
red5test.tar_.gz301.6 KB