How to Take a BitMap Snapshot of an FLV

I needed a quick easy way to take BitMap snapshot of a loaded flv for an app. I thought the easiest way to accomplish this would be to load the FLV into my player and then play a very short snippet, pause the video and then take a snapshot. Here are some snippets of my code to give you an idea of how easy this is to accomplish. Maybe someone has a better way to do this which I would love to hear about:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
private var _timer:Timer;        
public var bm:Bitmap;

private function initApp():void
{
  _timer = new Timer(10, 1);
  _timer.addEventListener( TimerEvent.TIMER, pauseSnap );
}

public function play():void
{
  ns.play( url );
  _timer.start();
} 

private function pauseSnap( e:TimerEvent ):void 
{
  ns.pause();
          
  bm = takeSnapShot( this as DisplayObject ); 
        /** 
         * 'this' refers to the VideoContainer which extends UIComponent
         * the container is simply the FLV so the resulting BitMap will display the FLV
         */   
}
      
private function takeSnapShot( source:DisplayObject ):Bitmap 
{
      var bmd:BitmapData = new BitmapData( video.width, video.height );
           
      bmd.draw( source );
            
      return new Bitmap( bmd );
}

Comments