Skip to content

Instantly share code, notes, and snippets.

@nsdevaraj
Created May 27, 2010 12:09
Show Gist options
  • Save nsdevaraj/415730 to your computer and use it in GitHub Desktop.
Save nsdevaraj/415730 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
showStatusBar="false" skinClass="assets.DTApplicationSkin" alwaysInFront="true"
creationComplete="webCam_pnl.attachCamera(Camera.getCamera()),startJava()"
maxWidth="256" maxHeight="180" >
<fx:Script>
<![CDATA[
import flash.filesystem.File;
import flash.utils.clearInterval;
import flash.utils.setInterval;
import mx.controls.Image;
[Bindable]
private var frameWidth:int = 576;
[Bindable]
private var frameHeight:int = 360;
private var myWriter:SimpleFlvWriter = SimpleFlvWriter.getInstance();
private var recordInterval:uint;
private var curVidFile:File;
private var interval:int = 400;
private var milliSec:int = 1000;
private const JREPath:String = "C:\\Program Files\\Java\\jre6\\bin"
private function recordHit():void{
if(record_btn.label == "Record"){
curVidFile = File.createTempFile();
myWriter.createFile(curVidFile, frameWidth,frameHeight, milliSec/interval);
recordInterval = setInterval(recordVid, interval);
record_btn.label = "Stop";
}else{
nativeProcess.removeEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onStandardOutputData);
clearInterval(recordInterval);
myWriter.closeFile();
var newFileNameStr:String = curVidFile.name.split(".tmp").join(".flv");
trace("newFileName: " + newFileNameStr);
var desFile:File = new File(File.desktopDirectory.nativePath +"\\" + newFileNameStr);
curVidFile.copyTo(desFile);
record_btn.label = "Record";
}
}
private function recordVid():void{
nativeProcess.standardInput.writeMultiByte("Print Screen\n", "utf-8");
}
private var nativeProcess:NativeProcess;
private function startJava():void
{
var arg:Vector.<String> = new Vector.<String>;
arg.push("-jar");
arg.push(File.applicationDirectory.resolvePath("print.jar").nativePath);
var file:File = new File(JREPath);
file = file.resolvePath("javaw.exe");
var npInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
npInfo.executable = file;
npInfo.arguments = arg;
nativeProcess = new NativeProcess();
nativeProcess.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onStandardOutputData);
nativeProcess.start(npInfo);
}
private var data : BitmapData
private function onStandardOutputData(e:ProgressEvent):void
{
image.source = new Bitmap(Clipboard.generalClipboard.getData(ClipboardFormats.BITMAP_FORMAT) as BitmapData,"auto",true);
data= new BitmapData (frameWidth, frameHeight);
data.draw (image);
myWriter.saveFrameByte(data);
}
]]>
</fx:Script>
<mx:VideoDisplay id="webCam_pnl" width="256" height="160"/>
<mx:Button id="record_btn" label="Record" click="recordHit()" />
<mx:Image id="image" width="{frameWidth}" height="{frameHeight}" includeInLayout="false" visible="false"/>
</s:WindowedApplication>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment