• C
  • G

RETURN TO PROJECT

TheBeatlesRockBand.com


VideoPlayer.as

ActionScript 3.0

  
    package
    {
        import com.p9.*;

        import flash.display.*;
        import flash.events.*
        import flash.text.*;
        import flash.utils.*;
        import flash.system.System;
        import caurina.transitions.*;

        public class FullPlayer extends MovieClip
        {
            public static var _root:MovieClip;
            public static var flashVars:Object;

            public var Application:MovieClip;

            public var dataObj, metaObj:Object;
            public var limit:int;

            public var path:String;
            public var url, embed:String;

            public var asset:ExternalAsset;
            public var video:SmallPlayer;

            public var volumeLevel:Number;

            public var share:Boolean;
            public var done:Boolean;

            private var timerDisplay:Timer;
            private var loadInterval, playInterval:uint
            private var loadPct, playPct, seekPct:Number;

            private static var p9xml:XML2Object;

            public function FullPlayer ()
            {
                Application = this;

                stage.scaleMode = StageScaleMode.NO_SCALE;
                stage.align = StageAlign.TOP_LEFT;

                init();
            }

            private function init () 
            {
                done = false;

                flashVars = new Object();
                flashVars = LoaderInfo(this.root.loaderInfo).parameters;

                path = "";

                EventCenter.subscribe("onVideoComplete",onVideoComplete);

                clicked_mc.width = 0;
                loaded_mc.width = 0;
                played_mc.width = 0;

                initXML();

                loadComplete();
            }	

            private function loadComplete ()
            {
                volumeLevel = 0.6;

                populate();

                initControls();
            }

            public function initXML():void
            {
                p9xml = new XML2Object();
                p9xml.onLoaded = function() {
                    url = p9xml.xml.code.item[flashVars.no].url;
                    embed = p9xml.xml.code.item[flashVars.no].embed;
                }
                p9xml.load(path + "p9.xml");
            }

            private function populate ()
            {
                try {
                    removeChild(asset);
                    clearInterval(loadInterval);
                } catch (e:Error){

                } finally {
                    asset = new ExternalAsset();
                    asset.x = 20;
                    asset.y = 20;
                    addChild(asset);

                    swapChildren(asset, holder);

                    video = new SmallPlayer();
                    video.alpha = 0.0;
                    video.setSource(flashVars.video);
                    video.setVolume(volumeLevel);
                    video.setPause();

                    sound_mc.none.visible = false;
                    sound_mc.none.mouseEnabled = false;

                    timerDisplay = new Timer(1);
                    timerDisplay.addEventListener(TimerEvent.TIMER, updatePlay);
                    timerDisplay.start();

                    loadInterval = setInterval(updateLoad, 250);
                    //playInterval = setInterval(updatePlay, 1);

                    asset.onLoaded = function(target){
                        asset.addChild(video);
                        setAutoPlay();
                    }

                    asset.load(flashVars.image);
                }
            }

            private function initControls ()
            {
                pp_mc.pause_btn.visible = false;
                pp_mc.play_btn.visible = true;

                pp_mc.pause_btn.addEventListener(MouseEvent.CLICK, handlePause);
                pp_mc.play_btn.addEventListener(MouseEvent.CLICK, handlePlay);

                share = false;
                share_mc.mouseEnabled = share_mc.buttonMode = true;
                share_mc.addEventListener(MouseEvent.CLICK, handleShare);

                clicked_mc.alpha = 0.0;
                clicked_mc.addEventListener(MouseEvent.CLICK, handleScrub);

                sound_mc.speaker_btn.addEventListener(MouseEvent.CLICK, handleSound);

                tray.copy_url.addEventListener(MouseEvent.CLICK, copyURL);
                tray.copy_embed.addEventListener(MouseEvent.CLICK, copyEmbed);
            }

            private function handlePlay (e:MouseEvent)
            {
                //e.target.parent.parent.mainplay_btn.visible = false;
                e.target.parent.pause_btn.visible = true;
                e.target.visible = false;

                if(done) {
                    video.setSeek(0);
                    done = false;
                } else {
                    Application.video.setPlay();
                }

                Tweener.addTween(video, { alpha: 1.0, time: 0.2, transition:"easeInOutQuad" });
            }

            private function setAutoPlay ()
            {
                pp_mc.play_btn.visible = false;
                pp_mc.pause_btn.visible = true;
                //e.target.visible = false;

                if(done) {
                    video.setSeek(0);
                    done = false;
                } else {
                    Application.video.setPlay();
                }

                Tweener.addTween(video, { alpha: 1.0, time: 1.0, transition:"easeInOutQuad" });
            }

            private function handlePause (e:MouseEvent)
            {
                e.target.visible = false;
                e.target.parent.play_btn.visible = true;

                video.setPause();
            }

            private function handleScrub (e:MouseEvent)
            {
                seekPct = e.target.mouseX/660;
                video.setSeek(video.duration * seekPct);
                video.setPlay();
                Tweener.addTween(video, { alpha: 1.0, time: 0.2, transition:"easeInOutQuad" });

                pp_mc.pause_btn.visible = true;
                pp_mc.play_btn.visible = false;
            }

            private function handleSound (e:MouseEvent)
            {
                sound_mc.setState(volumeLevel)

                video.setVolume(volumeLevel);
            }

            private function handleShare (e:MouseEvent)
            {
                if(url != null || embed != null) {
                    tray.url_text.text = url;
                    tray.embed_text.text = embed;
                }

                if(share) {
                    share = false;
                    Tweener.addTween(tray, { y: 521.0, time: 1.0, transition:"easeInOutQuad" });
                } else {
                    share = true;
                    Tweener.addTween(tray, { y: 419.0, time: 1.0, transition:"easeInOutQuad" });
                }
            }

            private function copyURL (e:MouseEvent)
            {
                System.setClipboard(url);
            }

            private function copyEmbed (e:MouseEvent)
            {
                System.setClipboard(embed);
            }

            public function onVideoComplete (e:Event)
            {
                pp_mc.play_btn.visible = true;
                pp_mc.pause_btn.visible = false;

                done = true;
            }

            private function updateLoad ()
            {
                loadPct = video.ns.bytesLoaded/video.ns.bytesTotal;
                loaded_mc.width = clicked_mc.width = 660 * loadPct;
            }

            private function updatePlay (e:Event)
            {
                playPct = video.ns.time/video.duration*100;
                played_mc.width = 660 * playPct/100;
            }
        }
    }
  

RETURN TO PROJECT

TheBeatlesRockBand.com