Quick Conclusion about CircleCube Video Player

来源:互联网 发布:java 字节码 编辑:程序博客网 时间:2024/03/29 15:03



Real-time response to scroll bar's drag event


This program has a common feature, that user can drag the handler of volume controler, upward or downward, to turn up or turn down the volume of the video. Let's take a glance at the skeleton of code:

vcr.volumeB.slider.handle.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, handlePress);

        public function handlePress(arg1:flash.events.MouseEvent):void        {            vcr.volumeB.slider.handle.removeEventListener(flash.events.MouseEvent.MOUSE_DOWN, handlePress);            stage.addEventListener(flash.events.MouseEvent.MOUSE_UP, handleRelease);            stage.addEventListener(flash.events.MouseEvent.MOUSE_MOVE, handleDrag);            var loc1:*=new flash.geom.Rectangle(vcr.volumeB.slider.handle.x, 0, 0, -vcr.volumeB.slider.outline.height + vcr.volumeB.slider.handle.image.height);            vcr.volumeB.slider.handle.startDrag(true, loc1);            muteTimer.stop();            return;        }

        public function handleRelease(arg1:flash.events.MouseEvent):void        {            vcr.volumeB.slider.handle.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, handlePress);            stage.removeEventListener(flash.events.MouseEvent.MOUSE_UP, handleRelease);            stage.removeEventListener(flash.events.MouseEvent.MOUSE_MOVE, handleDrag);            vcr.volumeB.slider.handle.stopDrag();            return;        }

        public function handleDrag(arg1:flash.events.MouseEvent):void        {            setVol(vcr.volumeB.slider.handle.y / (-(vcr.volumeB.slider.outline.height - vcr.volumeB.slider.handle.image.height)));            arg1.updateAfterEvent();            return;        }

        public function setVol(arg1:Number):void        {            if (arg1 < 0 || arg1 > 1)             {                arg1 = 0;                trace("volume input Error");            }            st.volume = arg1;            ns.soundTransform = st;            vcr.volumeB.slider.bar.scaleY = arg1;            vcr.volumeB.slider.handle.y = arg1 * (-(vcr.volumeB.slider.outline.height - vcr.volumeB.slider.handle.image.height));            if (arg1 != 0)             {                if (arg1 <= 0.33)                 {                    vcr.volumeB.speaker.gotoAndStop("low");                }                else if (arg1 <= 0.66)                 {                    vcr.volumeB.speaker.gotoAndStop("medium");                }                else if (arg1 <= 1)                 {                    vcr.volumeB.speaker.gotoAndStop("high");                }            }            else             {                vcr.volumeB.speaker.gotoAndStop("mute");            }            return;        }


the main logic as shown in the following diagram:

drag


the key point is that when user click mouse down and drag the scroll, then the program will response to MOUSE_MOVE event, in the handler function, the program reposition the scroll bar and set the volume by its new position. The function updateAfterEvent() is to force FlashPlayer to redraw the screen immediately.


However, the logic for playback of the video is a little bit different:


            vcr.bar.scrub.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, scrubPress);            scrubTimer = new flash.utils.Timer(100);            scrubTimer.addEventListener(flash.events.TimerEvent.TIMER, scrubit);        public function scrubPress(arg1:flash.events.MouseEvent):void        {            vcr.bar.scrub.removeEventListener(flash.events.MouseEvent.MOUSE_DOWN, scrubPress);            var loc1:*=new flash.geom.Rectangle(vcr.bar.loadbar.x, vcr.bar.scrub.y, vcr.bar.loadbar.x + vcr.bar.loadbar.width, 0);            vcr.bar.scrub.startDrag(true, loc1);            stage.addEventListener(flash.events.MouseEvent.MOUSE_UP, scrubRelease);            stage.addEventListener(flash.events.MouseEvent.MOUSE_MOVE, scrubDrag);            videoTimer.stop();            scrubTimer.start();            return;        }        public function scrubRelease(arg1:flash.events.MouseEvent):void        {            stage.removeEventListener(flash.events.MouseEvent.MOUSE_UP, scrubRelease);            stage.removeEventListener(flash.events.MouseEvent.MOUSE_MOVE, scrubDrag);            scrubTimer.stop();            videoTimer.start();            vcr.bar.scrub.stopDrag();            vcr.bar.scrub.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, scrubPress);            return;        }        public function scrubDrag(arg1:flash.events.MouseEvent):void        {            arg1.updateAfterEvent();            return;        }        public function scrubit(arg1:flash.events.TimerEvent):*        {            ns.seek(Math.floor(vcr.bar.scrub.x / vcr.bar.bar.width * duration));            com.greensock.TweenNano.to(vcr.bar.playbar, 0.1, {"width":vcr.bar.scrub.x, "ease":com.greensock.easing.Quad.easeOut});            return;        }

Simply speaking, it adds a Timer to update the position each 0.1 sec to slow down the response process, and maybe user's experience would be more smooth by that.


Exception Handling


In this program, all the network IO operations are placed inside a try block(like urlloader to load xml, and loader to load image), and the catch function is especting an ArgumentError exception: 


            try             {                xmlLoader.load(new flash.net.URLRequest(xmlPath));                trace("loading xml from: " + xmlPath);            }            catch (e:ArgumentError)            {                trace("xml_load", e);            }






references:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/MouseEvent.html#updateAfterEvent()


http://help.adobe.com/zh_TW/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html?filter_flash=cs5&filter_flashplayer=10.2&filter_air=2.6

原创粉丝点击