I am trying to build AS3 web audio/video capture. I have successfully tried to display the webcam stream with the help of this great tutorial. The next step is how do i capture the video when the user starts recording. Below is my code:
// video stuff
private var camW:int = 300;
private var camH:int = 300;
private var video:Video;
// block stuff
private var rows:int = 3;
private var cols:int = 3;
private var blockW:int = camW/cols;
private var blockH:int = camH/rows;
private var pointArray:Array = new Array();
public function Main():void {
// Checks if camera is installed
if (Camera.names.length > 0) {
trace("User has at least one camera installed.");
var camera:Camera = Camera.getCamera();
camera.setMode(camW, camH, 30);
camera.addEventListener(StatusEvent.STATUS, statusHandler);
video = new Video(camW, camH);
video.attachCamera(camera);
initBlocks();
addEventListener(Event.ENTER_FRAME, updateBlocks);
}else {
trace("User has no cameras installed.");
var text:TextField = new TextField();
text.text = "Device Not Found! Please check if the camera is installed.";
text.x = 20;
text.y = 20;
text.width = 500;
addChild(text);
}
function statusHandler(event:StatusEvent):void {
// This event gets dispatched when the user clicks the "Allow" or "Deny"
// button in the Flash Player Settings dialog box.
trace(event.code); // "Camera.Muted" or "Camera.Unmuted"
switch (event.code) {
case "Camera.Muted":
trace("User clicked Deny.");
var text:TextField = new TextField();
text.text = "Device Denied Permission! Please provide permission to record video!";
text.x = 20;
text.y = 20;
text.width = 500;
addChild(text);
break;
case "Camera.Unmuted":
trace("User clicked Accept.");
break;
}
}
}
private function initBlocks():void {
for (var r:int = 0; r < rows; r++) {
for (var c:int = 0; c < cols; c++) {
var newBlock:Sprite = new Sprite();
newBlock.name = "block" + r + c;
var p:Point = new Point(c * blockW, r * blockH);
newBlock.x = c * (blockW) + 20;
newBlock.y = r * (blockH) + 20;
pointArray[newBlock.name] = p;
var bmpd:BitmapData = new BitmapData(blockW, blockH);
var bmp:Bitmap = new Bitmap(bmpd);
bmp.name = "myBmp";
newBlock.addChild(bmp);
addChild(newBlock);
}
}
}
private function updateBlocks(e:Event):void {
var srcBmpd:BitmapData = new BitmapData(camW, camH);
srcBmpd.draw(video);
for (var r:int = 0; r < rows; r++) {
for (var c:int = 0; c < cols; c++) {
var b_mc:Sprite = this.getChildByName("block" + r + c) as Sprite;
var bmp:Bitmap = b_mc.getChildByName("myBmp") as Bitmap;
var p:Point = pointArray[b_mc.name];
bmp.bitmapData.copyPixels(srcBmpd, new Rectangle(p.x, p.y, blockW, blockH), new Point());
}
}
}
I am completely new to AS3, just started 2 days ago. What is the logic for audio/video capture in AS3? Any pointers/demo/tutorials/books appreciated