scrubbing video [NetStream]
Posted by eric | Filed under Lab Work, Programming
I always like to do my video players from the ground up…i guess it’s just my style. I have used often the FLVPlayback, but there is a satisfaction in creating your own player. One thing that always plays with my head is the scrubbing. It’s the actual Math that gets me, and generally, i get it after a few tries…but never on the first (much like the custom scrollbar) .
Using the simplest of all examples, i am going to break down how to scrub a video using a track [simple movie clip looking like a bar] as a bottom layer, and another bar of same size, on a layer above. The goal here is to scrub video forward or backward, have the track represent loading, and the bar ontop be your ‘playhead’ (where you are in current time in the video). Variables you need before you click play are:
- duration of the NetStream (total time of the video, found through your NetStream.client ’s onMetaData handler)
- time of the NetStream- exactly what second you are on in the streaming video
- original length of the loadbar and scrub bar before the NetStream plays
I will assume we know how to load the NetStream and get it running. Genereally, in my video player, i initiate all that upfront…but before i get there, in my init funciton, i throw in another function used to simply id the loadbar, scrubbar, etc. :
//ID objects on stage FUNCTIONS------------------------------------------>>> private function defineContents():void { //id each loadbr=this.getChildByName('loadbar') as MovieClip; loadbr.buttonMode=true; scrub=this.getChildByName('scrubber') as MovieClip; scrub.buttonMode=true; originalWidth=loadbr.width //initilize scrub.scaleX=0; //add listeners loadbr.addEventListener(MouseEvent.MOUSE_DOWN,mousedown); scrub.addEventListener(MouseEvent.MOUSE_DOWN,mousedown); }
The function introduces the class to these display objects…as well, it adds an event listener to respond to mouse clicks.(These handlers will be the initiators of the scrub)
Tags: Actionscript 3, Flash, math