Created
May 14, 2012 02:37
-
-
Save RhinoLu/2691463 to your computer and use it in GitHub Desktop.
VideoLoader Fast Forward
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import com.bit101.components.PushButton; | |
import com.greensock.events.LoaderEvent; | |
import com.greensock.loading.data.VideoLoaderVars; | |
import com.greensock.loading.VideoLoader; | |
import com.greensock.TweenMax; | |
import flash.display.Sprite; | |
import flash.events.Event; | |
import flash.events.MouseEvent; | |
public class Main extends Sprite | |
{ | |
private var videoLoader:VideoLoader; | |
private var btn_normal:PushButton; | |
private var btn_fastforward:PushButton; | |
public function Main():void | |
{ | |
if (stage) init(); | |
else addEventListener(Event.ADDED_TO_STAGE, init); | |
} | |
private function init(e:Event = null):void | |
{ | |
removeEventListener(Event.ADDED_TO_STAGE, init); | |
videoLoader = new VideoLoader("video_1.flv", new VideoLoaderVars().autoPlay(false).noCache(true).onComplete(onLoadVideoComplete).vars); | |
videoLoader.addEventListener(VideoLoader.VIDEO_COMPLETE, onVideoComplete); | |
videoLoader.load(); | |
btn_normal = new PushButton(this, 10 , 240, "Normal" , onClick); | |
btn_fastforward = new PushButton(this, 150, 240, "Fast Forward", onClick); | |
} | |
private function onLoadVideoComplete(e:LoaderEvent):void | |
{ | |
videoLoader.content.x = 10; | |
videoLoader.content.y = 10; | |
addChild(videoLoader.content); | |
videoLoader.playVideo(); | |
btn_normal.enabled = false; | |
} | |
private function onClick(e:MouseEvent):void | |
{ | |
var btn:PushButton = e.target as PushButton; | |
if (btn == btn_normal) { | |
normalPlayVideo(); | |
}else if (btn == btn_fastforward) { | |
fastForwardVideo(); | |
} | |
} | |
private function normalPlayVideo():void | |
{ | |
removeEventListener(Event.ENTER_FRAME, onFrame); | |
//trace("normalPlayVideo : " + videoLoader.playProgress); | |
videoLoader.playVideo(); | |
btn_normal.enabled = false; | |
btn_fastforward.enabled = true; | |
} | |
private function fastForwardVideo():void | |
{ | |
videoLoader.pauseVideo(); | |
currentVideoTime = videoLoader.videoTime; | |
addEventListener(Event.ENTER_FRAME, onFrame); | |
btn_normal.enabled = true; | |
btn_fastforward.enabled = false; | |
} | |
private var frameSkip:int = 0; | |
private var speed:Number = 0.1; | |
private var currentVideoTime:Number; | |
private function onFrame(e:Event):void | |
{ | |
//frameSkip++; | |
//if (frameSkip % 5 != 0) return; | |
trace(currentVideoTime, videoLoader.videoTime, videoLoader.duration); | |
if (videoLoader.duration - videoLoader.videoTime < 1) { | |
//frameSkip = 0; | |
normalPlayVideo(); | |
}else { | |
//videoLoader.videoTime += speed; | |
currentVideoTime += speed; | |
videoLoader.videoTime = currentVideoTime; | |
} | |
} | |
private function onVideoComplete(e:Event):void | |
{ | |
videoLoader.playProgress = 0; | |
videoLoader.playVideo(); | |
btn_normal.enabled = false; | |
btn_fastforward.enabled = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment