AS3 YouTube Chromless API

SWEET!, YouTube released an ActionScript 3 API for their Chromeless Player. Previously, we had to rely on wrapper libraries to bridge the gap between the ActionScript 2 chromeless player and our very own AS 3 code, in short…it was painful. Now, its extremely easy to implement your very own YouTube Player. I scripted up a very simple example for you. Well, I should say it’s a bit more involved than the example you will find on the API reference page.

The following is an OOP based implementation. The video controls are all MovieClips and can be easily revised to your liking. The example below does not display the sound control, but its included in the .fla and can be added to the code, in either a slider or bar form.

Get Adobe Flash player

Lets break down the code:

The document class Main.as, is a simple view which builds all the flash components including the instantiation of the YouTube Player and VideoPlayerControls. The class also handles all the events dispatched from the YouTubePlayer and VideoPlayerControls.

Main.as
/****************************
* Manuel Gonzalez           *
* design@stheory.com        *
* www.stheory.com           *
* www.codingcolor.com       *
*****************************/

package {

    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.display.Shape;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import fl.controls.TextInput;
    import fl.controls.RadioButton;
    import fl.controls.Button;
    import com.YouTube.*;
    import com.video.*;

    public class Main extends Sprite {
        private var youTubePlayer:YouTubePlayer;
        private var videoPlayerContainer:MovieClip;
        private var videoPlayerControls:VideoPlayerControls;
        private var videoPlayerWidth:Number=320;
        private var videoPlayerHeight:Number=240;
        private var defaultVideoByID:String ="0UjsXo9l6I8";
        private var defaultVideoByURL:String ="http://www.youtube.com/watch?v=0UjsXo9l6I8";
        private var b1:Button;
        private var ti1:TextInput;
        private var ti2:TextInput;
        private var rb1:RadioButton;
        private var rb2:RadioButton;


        public function Main() {
            createVideoBkg();
            setupInputFields();
            createRadioButton();
            setupLoadButton();
            videoPlayerContainer = new MovieClip();
            videoPlayerContainer.x = 40;
            videoPlayerContainer.y = 25;
            addChild(videoPlayerContainer);
            createYouTubePlayer();
            createVideoPlayerControls();
        }
        /*
        Method: destroy
        Parameters:
        Returns:
        */

        private function destroy():void
        {
            videoPlayerControls.destroy();
            youTubePlayer.destroy();
            removeChild(videoPlayerContainer);
            removeChild(videoPlayerControls);
        }
        /*
        Method: createVideoBkg
        Parameters:
        Returns:
        */

        private function createVideoBkg():void {
            var bkg = new Sprite();
            bkg.x = 40;
            bkg.y = 25;
            createRectangle(bkg,0x000000,videoPlayerWidth,videoPlayerHeight);
            addChild(bkg);
        }
        /*
        Method: createVideoPlayerControls
        Parameters:
        Returns:
        */

        private function createVideoPlayerControls():void {
            videoPlayerControls = new VideoPlayerControls();
            videoPlayerControls.visible=false;
            videoPlayerControls.videoWidth = videoPlayerWidth;
            videoPlayerControls.videoHeight = videoPlayerHeight;
            videoPlayerControls.addEventListener(VideoPlayerControls.ON_PLAYBACK_STATE_CHANGE,playerControlsOnChange);
            videoPlayerControls.addEventListener(VideoPlayerControls.ON_SOUND_CHANGE,playerControlsSoundOnChange);
            videoPlayerControls.x = videoPlayerContainer.x;
            videoPlayerControls.y = videoPlayerContainer.y + (videoPlayerHeight + 8);
            videoPlayerControls.init();
            addChild(videoPlayerControls);

        }
        /*
        Method: createYouTubePlayer
        Parameters:
        Returns:
        */

        private function createYouTubePlayer():void {
            youTubePlayer = new YouTubePlayer();
            youTubePlayer.addEventListener(YouTubeEvent.ON_READY, playerReady);
            youTubePlayer.addEventListener(YouTubeEvent.ON_CHANGE, onPlayerStateChange);
            youTubePlayer.createPlayer(videoPlayerContainer);
        }
        /*
        Method:playerControlsOnChange
        Parameters:
        event:VideoControlsEvent
        Returns:
        */

        private function playerControlsOnChange(event:VideoControlsEvent):void {

            var buttonState:String = event.data.state;
            switch (buttonState) {
                case "play" :
                    youTubePlayer.playVideo();
                    break;
                case "pause" :
                    youTubePlayer.pauseVideo();
                    break;
                case "seek" :
                    youTubePlayer.seekTo(event.data.val,true);
                    break;
            }
        }
        /*
        Method:playerControlsSoundOnChange
        Parameters:
        event:VideoControlsEvent
        Returns:
        */

        private function playerControlsSoundOnChange(event:VideoControlsEvent):void {

            var buttonState:String = event.data.state;
            switch (buttonState) {
                case "mute" :
                    youTubePlayer.mute();
                    break;
                case "unmute" :
                    youTubePlayer.unMute();
                    break;
                case "adjust_volume" :
                    youTubePlayer.setVolume(event.data.val);
                    removeEventListener(Event.ENTER_FRAME,trackProgress);
                    break;
            }
        }
        /*
        Method: playerReady
        Parameters:
        event:YouTubeEvent
        Returns:
        */

        private function playerReady(event:YouTubeEvent):void {
            youTubePlayer.setSize(videoPlayerWidth,videoPlayerHeight);
            youTubePlayer.cueVideoById(defaultVideoByID);
        }
        /*
        Method: onPlayerStateChange
        Parameters:
        event:Event
        Returns:
        */

        private function onPlayerStateChange(event:Event):void {
            var _state = event.data;
            switch (_state) {
                case -1 :
                    //trace("unstarted");
                    break;
                case 0 :
                    //trace("ended");
                    videoPlayerControls.setPlayPauseControls(youTubePlayer.PlayerState);
                    removeEventListener(Event.ENTER_FRAME,trackProgress);
                    break;
                case 1 :
                    //trace("playing" + youTubePlayer.volume);
                    youTubePlayer.setVolume(20);
                    videoPlayerControls.setPlayPauseControls(youTubePlayer.PlayerState);
                    videoPlayerControls.setMuteControl(youTubePlayer.isMuted());
                    videoPlayerControls.setSeekDuration(youTubePlayer.duration);
                    addEventListener(Event.ENTER_FRAME,trackProgress);
                    break;
                case 2 :
                    //trace("paused");
                    break;
                case 3 :
                    //trace("buffering");

                    break;
                case 5 :
                    //trace("video cued");
                    videoPlayerControls.visible=true;
                    break;
            }
        }
        /*
        Method:trackProgress
        Parameters:
        event:Event
        Returns:
        */

        private function trackProgress(event:Event):void {
            var _bytesLoaded = youTubePlayer.VideoBytesLoaded;
            var _bytesTotal = youTubePlayer.VideoBytesTotal;

            videoPlayerControls.setLoadingProgress({bytes:_bytesLoaded,total:_bytesTotal});
            videoPlayerControls.setSeekCurrentTime(youTubePlayer.CurrentTime);

        }
        /*
        Method: setupLoadButton
        Parameters:
        Returns:
        */

        private function setupLoadButton():void {
            b1 = new Button();
            b1.x = 25;
            b1.y = 445;
            b1.label = "Load Video";
            b1.addEventListener(MouseEvent.CLICK, loadVideo);
            addChild(b1);

        }
        /*
        Method:loadVideo
        Parameters:
        event:MouseEvent
        Returns:
        */

        private function loadVideo(event:MouseEvent):void {
            if (rb1.selected) {
                youTubePlayer.loadVideoById(defaultVideoByID);
            } else if (rb2.selected) {

                //youTubePlayer.loadVideoByUrl(defaultVideoByURL);Google has not implemented yet
                youTubePlayer.loadVideoById(extractVideoId(defaultVideoByURL));
            }
        }
        /*
        Method:extractVideoId
        Parameters:
        inUrl:String
        Returns: String
        */

        private function extractVideoId(inUrl:String):String {
            var vIndex:Number = inUrl.lastIndexOf("=");
            if (vIndex == -1) {
                // awh snap there is no Id
                return "";
            } else {
                return inUrl.substr(vIndex + 1,inUrl.length);
            }
        }
        /*
        Method: setupInputFields
        Parameters:
        Returns:
        */

        private function setupInputFields():void {
            ti1 = new TextInput();
            ti1.move(100,375);
            ti1.width = 150;
            ti1.text = defaultVideoByID;
            ti1.addEventListener(Event.CHANGE,updateDefaultVideoById);
            ti2 = new TextInput();
            ti2.move(100,400);
            ti2.width = 250;
            ti2.text = defaultVideoByURL;
            ti2.addEventListener(Event.CHANGE,updateDefaultVideoByURL);
            addChild(ti1);
            addChild(ti2);
        }
        /*
        Method:updateDefaultVideoById
        Parameters:
        event:Event
        Returns:
        */

        private function updateDefaultVideoById(event:Event):void {
            defaultVideoByID = ti1.text;
        }
        /*
        Method:updateDefaultVideoByURL
        Parameters:
        event:Event
        Returns:
        */

        private function updateDefaultVideoByURL(event:Event):void {
            defaultVideoByURL = ti2.text;
        }
        /*
        Method: createRadioButton()
        Parameters:
        Returns:
        */

        private function createRadioButton():void {
            rb1= new RadioButton();
            rb1.label="by ID :";
            rb1.selected = true;
            rb1.move(20, 375);

            rb2= new RadioButton();
            rb2.label="by URL:";
            rb2.selected = false;
            rb2.move(20, 400);
            addChild(rb1);
            addChild(rb2);
        }
        /*
        Method:createRectangle
        Parameters:
        inSrc:*
        inColor:Number
        inW:Number;
        inH:Number;
        Return:
        */

        private function createRectangle(inSrc:*,inColor:Number=0x999999,inW:Number=80,inH:Number=50):void {
            var rect:Shape=new Shape();
            rect.graphics.clear();
            rect.graphics.beginFill(inColor);
            rect.graphics.drawRect(0,0,inW,inH);
            rect.graphics.endFill();
            inSrc.addChild(rect);
        }
    }
}

The YouTubePlayer class simply wraps up all the current API calls. It also loads the chromeless player into a provided displayObject and dispatches events using a custom events class.

YouTubePlayer.as

/****************************
* Manuel Gonzalez           *
* design@stheory.com        *
* www.stheory.com           *
* www.codingcolor.com       *
*****************************/

package com.YouTube{
    import flash.events.Event;
    import flash.events.EventDispatcher;
    import flash.events.IEventDispatcher;
    import flash.system.Security;
    import flash.events.IOErrorEvent;
    import flash.display.Loader;
    import flash.net.URLRequest;

    public class YouTubePlayer extends EventDispatcher {
       
        private var _youTubePlayer:Object;
        private var _loader:Loader;
        private var _container:*
        protected var _playerPath:String = "http://www.youtube.com/apiplayer?version=3";

        public function YouTubePlayer(target:IEventDispatcher=null) {
            super(target);
        }
        /*
        Method:createPlayer
        */

        public function createPlayer(inContainer:*):void
        {
            _container = inContainer;
            Security.allowInsecureDomain("*");
            Security.allowDomain("*");
            var _loader = new Loader();
            _loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
            _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
            _loader.load(new URLRequest(_playerPath));
        }
       
        /*
        Method: duration
         Returns the duration in seconds of the currently playing video.
         Note that getDuration() will return 0 until the video's metadata is loaded,
         which normally happens just after the video starts playing.
        */

        public function get duration():Number
        {
            return _youTubePlayer.getDuration();
        }
        /*
        Method:videoUrl
         Returns the YouTube.com URL for the currently loaded/playing video.
        */

        public function get videoUrl():String
        {
            return _youTubePlayer.getVideoUrl();
        }
        /*
        Method:embedCode
         Returns the embed code for the currently loaded/playing video.
        */

        public function get embedCode():String
        {
            return _youTubePlayer.getVideoEmbedCode();
        }
       
        /*
        Method: volume()
        Returns the player's current volume, an integer between 0 and 100.
        Note that getVolume() will return the volume even if the player is muted.
        */

        public function get volume():Number
        {
         return _youTubePlayer.getVolume();
        }
       
        /*
        Method: VideoBytesLoaded
        Returns the number of bytes loaded for the current video.
        */

        public function get VideoBytesLoaded():Number
        {
            return _youTubePlayer.getVideoBytesLoaded();
        }
   
        /*
        Method: VideoBytesTotal
        Returns the size in bytes of the currently loaded/playing video.
        */

        public function get VideoBytesTotal():Number
        {
            return _youTubePlayer.getVideoBytesTotal();
        }
       
        /*
        Method: VideoStartBytes
        Returns the number of bytes the video file started loading from.
        Example scenario: the user seeks ahead to a point that hasn't loaded yet,
        and the player makes a new request to play a segment of the video that hasn't loaded yet.
        */

        public function get VideoStartBytes():Number
        {
            return _youTubePlayer.getVideoStartBytes();
        }
        /*
        Method:PlayerState
        Returns the state of the player. Possible values are unstarted (-1), ended (0), playing (1),
        paused (2), buffering (3), video cued (5).
        */

        public function get PlayerState():Number
        {
            return _youTubePlayer.getPlayerState();
        }
        /*
        Method: CurrentTime
        Returns the elapsed time in seconds since the video started playing.
        */

        public function get CurrentTime():Number
        {
            return _youTubePlayer.getCurrentTime()
        }
        /*
        Method: PlaybackQuality
        This function retrieves the actual video quality of the current video.
        It returns undefined if there is no current video. Possible return values are:
        hd720, large, medium and small.
        */

        public function get PlaybackQuality():String
        {
            return _youTubePlayer.getPlaybackQuality();
        }
        /*
        Method: PlaybackQuality
        This function sets the suggested video quality for the current video.
        The function causes the video to reload at its current position in the new quality.
        If the playback quality does change, it will only change for the video being played.
        */

        public function set PlaybackQuality(suggestedQuality:String):void
        {
            _youTubePlayer.setPlaybackQuality(suggestedQuality);
        }
       
        //////////////////////////////////////////////////////////////////////////////////////////////
       
        /*
        Method: cueVideoById
        Loads the specified video's thumbnail and prepares the player to play the video.
        The player does not request the FLV until playVideo() or seekTo() is called.
        */

        public function cueVideoById(videoId:String, startSeconds:Number=0, suggestedQuality:String="default"):void
        {
            _youTubePlayer.cueVideoById(videoId, startSeconds, suggestedQuality);
        }
        /*
        Method:loadVideoById
        Loads and plays the specified video.
        */

        public function loadVideoById(videoId:String, startSeconds:Number=0, suggestedQuality:String="default"):void
        {
            _youTubePlayer.loadVideoById(videoId, startSeconds, suggestedQuality);
        }
        /*
        Method:cueVideoByUrl
        Loads the specified video's thumbnail and prepares the player to play the video.
        The player does not request the FLV until playVideo() or seekTo() is called.
        */

        public function cueVideoByUrl(mediaContentUrl:String, startSeconds:Number=0):void
        {
            _youTubePlayer.cueVideoByUrl(mediaContentUrl, startSeconds);
        }
        /*
        Method:playVideo
         Plays the currently cued/loaded video.
        */

        public function playVideo():void
        {
            _youTubePlayer.playVideo();
        }
        /*
        Method:pauseVideo
        Pauses the currently playing video.
        */

        public function pauseVideo():void
        {
            _youTubePlayer.pauseVideo();
        }
        /*
        Method: stopVideo
        Stops the current video. This function also cancels the loading of the video.
        */

        public function stopVideo():void
        {
            _youTubePlayer.stopVideo();
        }
        /*
        Method: seekTo
        Seeks to the specified time of the video in seconds.
        The seekTo() function will look for the closest keyframe before the seconds specified.
        This means that sometimes the play head may seek to just before the requested time,
        usually no more than ~2 seconds.
        */

       
        public function seekTo(seconds:Number, allowSeekAhead:Boolean):void
        {
            _youTubePlayer.seekTo(seconds, allowSeekAhead);
        }
       
        /*
        Method:
         Mutes the player.
        */

        public function mute():void
        {
            _youTubePlayer.mute();
        }
   
        /*
        Method: unMute
        Unmutes the player.
        */

        public function unMute():void
        {
            _youTubePlayer.unMute();
        }
   
        /*
        Method: isMuted
        Returns true if the player is muted, false if not.
        */

        public function isMuted():Boolean
        {
            _youTubePlayer.isMuted();
        }
   
        /*
        Method: setVolume
         Sets the volume. Accepts an integer between 0 and 100.
        */

        public function setVolume(inVolume:Number):void
        {
            _youTubePlayer.setVolume(inVolume);
        }
 
       
        /*
        Method:setSize
        Sets the size in pixels of the player.
        This method should be used instead of setting the width and height properties
        of the MovieClip. Note that this method does not constrain the proportions of
        the video player, so you will need to maintain a 4:3 aspect ratio.
        The default size of the chromeless SWF when loaded into another SWF is 320px by 240px
        and the default size of the embedded player SWF is 480px by 385px.
        */

        public function setSize(inWidth:Number, inHeight:Number):void
        {
            _youTubePlayer.setSize(inWidth, inHeight);
        }
   
        /*
        Method: loadVideoByUrl
        This function, which loads and plays the specified video,
        has not yet been implemented for the ActionScript 3.0 Player API.
        */

        public function loadVideoByUrl(mediaContentUrl:String, startSeconds:Number=0):void
        {
       
            _youTubePlayer.loadVideoByUrl(mediaContentUrl, startSeconds);
        }
        /*
        Method: destroy
        This function, which has not yet been implemented for the AS3 Player API,
        destroys the player instance. This method should be called before unloading
        the player SWF from your parent SWF.
        */

        public function destroy():void
        {
            _youTubePlayer.destroy();
        }
        private function onLoaderInit(event:Event):void {
           
            var player:Loader = Loader(event.target.loader);
            _youTubePlayer = player.content;
            _youTubePlayer.addEventListener("onReady", onPlayerReady);
            _youTubePlayer.addEventListener("onError", onPlayerError);
            _youTubePlayer.addEventListener("onStateChange", onPlayerStateChange);
            _youTubePlayer.addEventListener("onPlaybackQualityChange", onVideoPlaybackQualityChange);
            _container.addChild(_youTubePlayer);
            _loader = null;
            }
        private function ioErrorHandler(event:IOErrorEvent):void {
            //trace("ioErrorHandler: " + event);
            dispatchEvent(new YouTubeEvent(YouTubeEvent.ON_IOERROR,event));
        }
        private function onPlayerReady(event:Event):void {
            //trace("player ready:", Object(event).data)
            dispatchEvent(new YouTubeEvent(YouTubeEvent.ON_READY,event.data));
        }

        private function onPlayerError(event:Event):void {
            //trace("player error:", Object(event).data);
            dispatchEvent(new YouTubeEvent(YouTubeEvent.ON_ERROR,event.data));
        }

        private function onPlayerStateChange(event:Event):void {
            //trace("player state:", Object(event).data);
            dispatchEvent(new YouTubeEvent(YouTubeEvent.ON_CHANGE,event.data));
        }

        private function onVideoPlaybackQualityChange(event:Event):void {
            //trace("video quality:", Object(event).data);
            dispatchEvent(new YouTubeEvent(YouTubeEvent.ON_QUALITY_CHANGED,event.data));
        }

    }
}

The VideoPlayerControls class builds all the independent assets to control the chromeless player.

VideoPlayerControls.as

/****************************
* Manuel Gonzalez           *
* design@stheory.com        *
* www.stheory.com           *
* www.codingcolor.com       *
*****************************/


package com.video{
    import flash.display.*;
    import flash.events.MouseEvent;
    import flash.events.Event;
   
   
    public class VideoPlayerControls extends Sprite{
       
       
        public static  const ON_PLAYBACK_STATE_CHANGE:String = "ON_PLAYBACK_STATE_CHANGE";
        public static  const ON_SOUND_CHANGE:String = "ON_SOUND_CHANGE";
        public static  const ON_SEEK_CHANGE:String = "ON_SEEK_CHANGE";
       
        private var playbackControl:MovieClip;
        private var loadProgessBar:MovieClip;
        private var scrubControl:MovieClip;
        private var volumeControl:MovieClip;
        private var muteControl:MovieClip;
        private var vidWidth:Number;
        private var vidHeight:Number;
       
        public function set videoWidth(inNum:Number):void
        {
             vidWidth=inNum;
        }
        public function get videoWidth():Number
        {
             return vidWidth;
        }
        public function set videoHeight(inNum:Number):void
        {
            vidHeight =inNum;
        }
        public function get videoHeight():Number
        {
            return vidHeight;
        }
        public function VideoPlayerControls(){}
        /*
        Method: init
        Parameters:
        Returns:
        */

        public function init():void
        {
            createPlayPauseButton();
            createMuteButton();
            createVideoLoadBar();
            createScrubControl();
            adjustLayout( vidWidth,vidHeight)
        }
        /*
        Method: setLoadingProgress
        Parameters:
        inObj:Object
        Returns:
        */

        public function setLoadingProgress(inObj:Object):void
        {
            loadProgessBar.byteLoaded = inObj.bytes;
            loadProgessBar.byteTotal = inObj.total;
        }
        /*
        Method:setVolumeControl
        Parameters:
        inNum:Number
        Returns:
        */

        public function setVolumeControl(inNum:Number):void
        {
             volumeControl.curVolume = inNum;
        }
        /*
        Method: setMuteControl
        Parameters:
        inBool:Boolean
        Returns:
        */

        public function setMuteControl(inBool:Boolean):void{
            muteControl.isMuted = inBool;
        }
        /*
        Method: setPlayPauseControls
        Parameters:
        inNum:Number
        Returns:
        */

        public function setPlayPauseControls(inNum:Number):void
        {
            if(inNum == 0){
                playbackControl.buttonState="play";
            }else if(inNum == 1){
                playbackControl.buttonState="pause";
            }
        }
        /*
        Method: setSeekDuration
        Parameters:
        inNum:Number
        Returns:
        */

        public function setSeekDuration(inNum:Number):void
        {
            scrubControl.durr = inNum;
        }
        /*
        Method: setSeekCurrentTime
        Parameters:
        inNum:Number
        Returns:
        */

        public function setSeekCurrentTime(inNum:Number):void
        {
            scrubControl.currTime = inNum;
        }
        /*
        Method: adjustLayout
        Parameters:
        inW:Number
        inH:Number
        Returns:
        */

        public function adjustLayout(inW:Number,inH:Number):void
        {
            playbackControl.x=0;
            loadProgessBar.x = (playbackControl.x + playbackControl.width)+10;
            loadProgessBar.y = playbackControl.height/2 - loadProgessBar.height/2;
            scrubControl.x = loadProgessBar.x;
            scrubControl.y = loadProgessBar.y;
            muteControl.x = inW - muteControl.width
           
        }
        /*
        Method: destroy
        Parameters:
        Returns:
        */

        public function destroy():void
        {
            playbackControl.removeEventListener(Event.CHANGE,setPlaybackState);
            muteControl.removeEventListener(Event.CHANGE,setMuteState);
            scrubControl.removeEventListener(Event.CHANGE,onSeek);
            removeChild(playbackControl);
            removeChild(loadProgessBar);
            removeChild(muteControl);
            removeChild(scrubControl);
        }
        /*
        Method: createScrubControl
        Parameters:
        Returns:
        */

        private function createScrubControl():void
        {
            scrubControl = new VideoScrubber();
            scrubControl.addEventListener(Event.CHANGE,onSeek);
            addChild(scrubControl);
        }
        /*
        Method:createMuteButton
        Parameters:
        Returns:
        */

        private function createMuteButton():void
        {
            muteControl = new MuteControlButton();
            muteControl.addEventListener(Event.CHANGE,setMuteState);
            addChild(muteControl);
        }
        /*
        Method: createVideoLoadBar
        Parameters:
        Returns:
        */

        private function createVideoLoadBar():void
        {
            loadProgessBar = new VideoProgressBar();
            addChild(loadProgessBar);
        }
        /*
        Method: createPlayPauseButton
        Parameters:
        Returns:
        */

        private function createPlayPauseButton():void
        {
            playbackControl = new PlayPauseButton();
            playbackControl.addEventListener(Event.CHANGE,setPlaybackState);
            addChild(playbackControl);
        }
        /*
        Method:createVolumeSliderControl
        Parameters:
        Returns:
        */

        private function createVolumeSliderControl():void
        {
            volumeControl = new VolumeSliderControl();
            volumeControl.addEventListener(Event.CHANGE,adjustPlayerVolume);
            addChild(volumeControl)
           
        }
       
        /*
        Method:createVolumeBarControl
        Parameters:
        Returns:
        */

        private function createVolumeBarControl():void
        {
            volumeControl = new VolumeBarControl();
            volumeControl.addEventListener(Event.CHANGE,adjustPlayerVolume);
            addChild(volumeControl)
           
        }
        /*
        Method:adjustPlayerVolume
        Parameters:
        event:Event
        Returns:
        */

        private function adjustPlayerVolume(event:Event):void
        {
            var evtObj:Object = {state:"adjust_volume", val:volumeControl.curVolume}
            dispatchEvent(new VideoControlsEvent(evtObj,ON_SOUND_CHANGE));
        }
        /*
        Method:setPlaybackState
        Parameters:
        event:Event
        Returns:
        */

        private function setPlaybackState(event:Event):void
        {
            var evtObj:Object = {state:playbackControl.buttonState}
            dispatchEvent(new VideoControlsEvent(evtObj,ON_PLAYBACK_STATE_CHANGE));
        }
        /*
        Method:setMuteState
        Parameters:
        event:Event
        Returns:
        */

        private function setMuteState(event:Event):void
        {
            var type:String;
            if(muteControl.isMuted){
                type = "mute";
            }else{
                type = "unmute";
            }
            var evtObj:Object = {state:type};
            dispatchEvent(new VideoControlsEvent(evtObj,ON_SOUND_CHANGE));
        }
        /*
        Method: onSeek
        Parameters:
        event:Event
        Returns:
        */

        private function onSeek(event:Event):void
        {
            var evtObj:Object = {state:"seek",val:scrubControl.sec}
            dispatchEvent(new VideoControlsEvent(evtObj,ON_PLAYBACK_STATE_CHANGE));
        }
       
       
    }
   
   
   
   
   
}

And thats pretty much the meat of the application. The rest of the classes are each video control asset (play/pause, mute, ect.).
The next release I will introduce the ability to search YouTube and display the results in a custom scroller.
Enjoy!

Download Source:
AS3 YouTube Chromeless Player (799)

Be Sociable, Share!
Coding Color | 2009 All Rights Reserved.