package {
import com.viewtoo.common.view.CommonSprite;
import flash.events.Event;
import fl.video.*;
import flash.display.*;
import flash.events.*;
import flash.geom.*;
/**
* ...
* @author Lancelot
*/
public class VideoGridView extends Sprite {
private var flvPlayer:FLVPlayback = null;
private var len:Number = 3;
private var _w:Number;
private var _h:Number;
//
private var runObject:Array = [];
public function VideoGridView() {
super();
}
protected override function onAdded(evt:Event):void {
super.onAdded(evt);
flvPlayer = new FLVPlayback();
flvPlayer.bufferTime = 3;
flvPlayer.load("../mvGame/1.flv");
flvPlayer.autoPlay = true;
flvPlayer.addEventListener(MetadataEvent.METADATA_RECEIVED, onMetaData);
}
private function onMetaData(evt:MetadataEvent):void {
flvPlayer.width = evt.info.width;
flvPlayer.height = evt.info.height;
_w = flvPlayer.width / len;
_h = flvPlayer.height / len;
flvPlayer.visible = false;
addChild(flvPlayer);
this.addEventListener(Event.ENTER_FRAME, onVideoEnterFrame);
drawVideo();
}
// 开始照相
private function onVideoEnterFrame(evt:Event):void {
var l:Number = runObject.length;
for (var i:Number = 0; i < l; i++) {
var mybmp:BitmapData = runObject[i].mybmpdata;
var matrix:Matrix = runObject[i].matrix;
var rect:Rectangle = runObject[i].ract;
// 绘制9个区域
mybmp.draw(flvPlayer, matrix, null, null, rect);
}
}
private function onImageMouseDownEvent(evt:MouseEvent):void {
var maskView:Sprite = Sprite(evt.currentTarget);
maskView.startDrag(false, null);
maskView.addEventListener(MouseEvent.MOUSE_UP, onImageMouseUpEvent);
}
private function onImageMouseUpEvent(evt:MouseEvent):void {
var maskView:Sprite = Sprite(evt.currentTarget);
maskView.removeEventListener(MouseEvent.MOUSE_UP, onImageMouseUpEvent);
maskView.stopDrag();
}
// 快照
private function drawVideo():void {
for (var x:Number = 0; x < len; x++) {
for (var y:Number = 0; y < len; y++) {
var obj:Object = new Object();
var rect:Rectangle = new Rectangle(_w * x, _h * y, _w, _h);
var matrix:Matrix = new Matrix(1, 0, 0, 1, -rect.x, -rect.y);
// 避免误差
rect.width += 1;
var mybmp:BitmapData = new BitmapData(rect.width, rect.height);
mybmp.draw(flvPlayer, matrix, null, null, rect);
var sp:Sprite = new Sprite();
sp.x = _w * x;
sp.y = _h * y;
sp.addEventListener(MouseEvent.MOUSE_DOWN, onImageMouseDownEvent);
var bit:Bitmap = new Bitmap(mybmp);
sp.addChild(bit);
addChild(sp);
runObject.push( { mybmpdata:mybmp, matrix:matrix, rect:rect } );
}
}
}
}
}
import com.viewtoo.common.view.CommonSprite;
import flash.events.Event;
import fl.video.*;
import flash.display.*;
import flash.events.*;
import flash.geom.*;
/**
* ...
* @author Lancelot
*/
public class VideoGridView extends Sprite {
private var flvPlayer:FLVPlayback = null;
private var len:Number = 3;
private var _w:Number;
private var _h:Number;
//
private var runObject:Array = [];
public function VideoGridView() {
super();
}
protected override function onAdded(evt:Event):void {
super.onAdded(evt);
flvPlayer = new FLVPlayback();
flvPlayer.bufferTime = 3;
flvPlayer.load("../mvGame/1.flv");
flvPlayer.autoPlay = true;
flvPlayer.addEventListener(MetadataEvent.METADATA_RECEIVED, onMetaData);
}
private function onMetaData(evt:MetadataEvent):void {
flvPlayer.width = evt.info.width;
flvPlayer.height = evt.info.height;
_w = flvPlayer.width / len;
_h = flvPlayer.height / len;
flvPlayer.visible = false;
addChild(flvPlayer);
this.addEventListener(Event.ENTER_FRAME, onVideoEnterFrame);
drawVideo();
}
// 开始照相
private function onVideoEnterFrame(evt:Event):void {
var l:Number = runObject.length;
for (var i:Number = 0; i < l; i++) {
var mybmp:BitmapData = runObject[i].mybmpdata;
var matrix:Matrix = runObject[i].matrix;
var rect:Rectangle = runObject[i].ract;
// 绘制9个区域
mybmp.draw(flvPlayer, matrix, null, null, rect);
}
}
private function onImageMouseDownEvent(evt:MouseEvent):void {
var maskView:Sprite = Sprite(evt.currentTarget);
maskView.startDrag(false, null);
maskView.addEventListener(MouseEvent.MOUSE_UP, onImageMouseUpEvent);
}
private function onImageMouseUpEvent(evt:MouseEvent):void {
var maskView:Sprite = Sprite(evt.currentTarget);
maskView.removeEventListener(MouseEvent.MOUSE_UP, onImageMouseUpEvent);
maskView.stopDrag();
}
// 快照
private function drawVideo():void {
for (var x:Number = 0; x < len; x++) {
for (var y:Number = 0; y < len; y++) {
var obj:Object = new Object();
var rect:Rectangle = new Rectangle(_w * x, _h * y, _w, _h);
var matrix:Matrix = new Matrix(1, 0, 0, 1, -rect.x, -rect.y);
// 避免误差
rect.width += 1;
var mybmp:BitmapData = new BitmapData(rect.width, rect.height);
mybmp.draw(flvPlayer, matrix, null, null, rect);
var sp:Sprite = new Sprite();
sp.x = _w * x;
sp.y = _h * y;
sp.addEventListener(MouseEvent.MOUSE_DOWN, onImageMouseDownEvent);
var bit:Bitmap = new Bitmap(mybmp);
sp.addChild(bit);
addChild(sp);
runObject.push( { mybmpdata:mybmp, matrix:matrix, rect:rect } );
}
}
}
}
}