Investigation of CircleCube Video Player (Day 7)

来源:互联网 发布:沈阳i5数控编程方法 编辑:程序博客网 时间:2024/04/29 10:22

Now we are at point where to add a function: when the player is in playing state, then start the timer, to hide the control panel.


version b.4

For now, the logic is: if the cursor is outside the vcr area, then mouseStill will increase, and until it reaches mouseStillMax(=3), then the vcr hides. And this Timer will be triggered in showVCR(), but now it is commented. And we will trigger it when play|pause the video, so change the playDown() to:

public function playDown($e:MouseEvent=null):void{...switch ($cs) {case "ready":{...mouseStill = 0;mouseTimer.start();break;}case "playing":{...mouseStill = 0;mouseTimer.stop();break;}case "paused":{...mouseStill = 0;mouseTimer.start();break;}case "complete":{...mouseStill = 0;mouseTimer.start();break;}default:{trace("ERROR: " + currentStatus);}}return;}


And add hidePlayOverlay() call into mouseStatus() to hideplayOverlay together:

public function mouseStatus($e:TimerEvent):void{if (mouseY < vcr.y || mouseY > vcr.height + vcr.y) {mouseStill++;}if (mouseStill > mouseStillMax) {mouseStill = 0;hideVCR();hidePlayOverlay();}return;}


And, we should remember we have not updated videoComplete(), we should show vcr and playOverlay when video finished, and clear the timer that would hide them:

public function videoComplete():void{ns.pause();videoTimer.stop();currentStatus = "complete";vcr.bar.bg.width = 0;vcr.bar.loadbar.width = 0;vcr.bar.playbar.width = 0;vcr.bar.scrub.x = 0;playOverlay.icon.gotoAndStop("playing");showPlayOverlay();showVCR();mouseStill = 0;  mouseTimer.stop();clearVideoStatus();vid.setChildIndex(video, vid.numChildren - 2);return;}


Now, talk about the condition that increase mouseStill, it is reasonable to keep the current logic, because you may operate on theVCR, then it should not disappear.


But you may notice that the delay of hiding vcr is not even, we need reset mouseStill to 0 when togglevcr to show:

public function toggleVCR($e:MouseEvent=null):void{if (vcr.timeCurrent.timeDisplay.visible){hideVCR();hidePlayOverlay();}else{showVCR();showPlayOverlay();mouseStill = 0;}}


And, for securing the operation, we should unlock the control after it shows 100%, so change showVCR():

public function showVCR($e:MouseEvent=null):void{if (!vcr.timeCurrent.timeDisplay.visible) {vcr.mouseChildren = true;com.greensock.TweenNano.to(vcr, 0.4, {"alpha":fadeInAlpha, "ease":com.greensock.easing.Quad.easeOut}   );   vcr.timeCurrent.timeDisplay.visible = true;vcr.timeTotal.timeDisplay.visible = true;}return;}

to:

public function showVCR($e:MouseEvent=null):void{if (!vcr.timeCurrent.timeDisplay.visible) {com.greensock.TweenNano.to(vcr, 0.4, {"alpha":fadeInAlpha, "ease":com.greensock.easing.Quad.easeOut,"onComplete": function(){vcr.mouseChildren = true;}}   );   vcr.timeCurrent.timeDisplay.visible = true;vcr.timeTotal.timeDisplay.visible = true;}return;}


change showPlayOverlay():

public function showPlayOverlay():void{playOverlay.mouseEnabled = true;com.greensock.TweenNano.to(playOverlay, 0.2, {"alpha":0.75, "scaleX":playOverlay.sXY, "scaleY":playOverlay.sXY, "ease":com.greensock.easing.Back.easeOut, "overwrite":false}   );return;}

to:

public function showPlayOverlay():void{com.greensock.TweenNano.to(playOverlay, 0.2, {"alpha":0.75, "scaleX":playOverlay.sXY, "scaleY":playOverlay.sXY, "ease":com.greensock.easing.Back.easeOut, "onComplete": function(){playOverlay.mouseEnabled = true;},"overwrite":false}   );return;}


Inside onMetaData() and onXMPData(), replace call to playerLayout(), with videoLayout().

public function onMetaData($obj:Object):void{if (duration == -1 || !pl_duration) {duration = Number($obj["duration"]);trace("onMetaData duration:", duration);pl_duration = true;videoLayout();}return;}public function onXMPData($obj:Object):void{if (duration == -1 || !pl_duration) {duration = Number($obj["duration"]);trace("onXMPdata duration:", duration);pl_duration = true;videoLayout();}return;}


and remove playerLayout(), since it just callvideoLayout():

public function playerLayout():void{videoLayout();return;}