更新,我已经让视频工作了。有点。即使是短视频,有时仍会出现此错误。
Error
有时它能良好地工作。但是至少我能够从组件中记录FLV。我还没有添加音频。
要运行此代码,您需要在此处找到FLVRecorder:
http://www.joristimmerman.be/wordpress/2008/12/18/flvrecorder-record-to-flv-using-air/
<?xml version="1.0" encoding="utf-8"?>
import mx.core.UIComponent;
import mx.events.FlexEvent;
private var file:File;
private var recorder:FLVRecorder=FLVRecorder.getInstance()
private var fps:uint = 10;
private var timer:Timer;
protected function viewnavigator1_creationCompleteHandler(event:FlexEvent):void
{
file=File.desktopDirectory.resolvePath("recording.flv");
recorder.setTarget(file,320,320,fps,systemManager)
var camera : Camera = Camera.getCamera();
if (camera)
{
var ui : UIComponent = new UIComponent();
var video : Video = new Video(320, 320);
camera.setMode(320, 320, 24.);
video.attachCamera(camera);
ui.addChild(video);
cameraGroup.addElement(ui);
}
timer = new Timer(1000/fps);
timer.addEventListener(TimerEvent.TIMER, captureScreen);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, stopRecording);
}
protected function stopRecording(event:Event):void
{
timer.stop();
recorder.addEventListener(FLVRecorderEvent.FLV_CREATED, fileMade)
recorder.addEventListener(FLVRecorderEvent.FLV_START_CREATION, startCreatingFLV)
recorder.stopRecording()
}
private function startCreatingFLV(e:FLVRecorderEvent):void{
recorder.addEventListener(FLVRecorderEvent.PROGRESS,onFLVCreationProgress)
}
private function onFLVCreationProgress(e:FLVRecorderEvent):void{
trace("saving progress ", e.progress,1);
}
protected function captureScreen(event:TimerEvent):void
{
trace("captured screen");
recorder.captureComponent(movieGroup)
}
protected function startRecording(event:MouseEvent):void
{
timer.start();
}
protected function fileMade(event:Event):void
{
trace("file made");
}
]]>
</fx:Script>
<s:VGroup>
<s:HGroup>
<s:Button label="start" click="startRecording(event)"/>
<s:Button label="stop" click="stopRecording(event)"/>
<s:Label id="progress" text="waiting..."/>
</s:HGroup>
<s:Group id="movieGroup" width="50%" height="50%">
<s:Group id="cameraGroup" width="100%" height="100%"/>
<s:Image source="image.png" width="25%" height="25%"/>
</s:Group>
</s:VGroup>