Recording using Flex/Flash

2019-04-16 05:46发布

问题:

I know that we can not record/Access anything out of flash player, because of it's security sandbox. Instead We can record the video while streaming it to server. like

   netStream.publish("YourFileName.flv","record");

But in recorde file, I will get only a video file Published by webcam to server and i want to record entire session.

Is there any way to record it locally, or Can i record the window ??

p.s. : I am not trying to access anything outside of flash player.

Thanks in advance...

回答1:

ok, so you can record the entire contents of the swf like this:

first, create a container object (anything that extends DisplayObject which implements IBitmapDrawable) then place everything that you want to capture (video view and everything else in your "session") then using an ENTER_FRAME event or Timer (preferable to control capture fps), draw the container to a BitmapData using BitmapData.draw(container). Pass that BitmapData to the FLV encode library found here using it's addFrame() method (docs and examples come with that library... super easy) and that's it! When you are done, you will have an flv video containing a frame by frame "screen capture" of what was going on in your swf! Just make sure EVERYTHING is in the container! That lib also accepts captured audio too if you want.

private function startCapturing():void{
    flvEncoder.start(); // see the libs docs and examples

    var timer:Timer = new Timer(1000/15); //capture at 15 fps
    timer.addEventListener(TimerEvent.Timer, onTimer);
    timer.start();
}

private function onTimer(event:TimerEvent):void{
    var screenCap:BitmapData = new BitmapData(container.width, container.height);
    screenCap.draw(container);

    flvEncoder.addFrame(screenCap); // see the libs docs and examples
}