Archive

Archive for the ‘Youtube’ Category

Youtube releases AS3 api

November 9th, 2009

Since youtube has released the as3 api the wrapper will become obsolete.

In order to keep things compatible, a new as3 lib will be available for download soon that will be compatible with the wrapper but will make use of the new as3 api.

Actionscript 3.0, Object Oriented Programming, Youtube, Youtube Wrapper , , ,

Youtube AS3 Wrapper v0.8.0m

July 12th, 2009

I would like to announce the availability of a new version of the Youtube AS3 Wrapper: v0.8.0m – m is from Multiple

This new version adds support for multiple players on the same stage.

That is, you can now play multiple youtube clips in the same time, on the same stage!

The new version is available for download on the downloads section.

The documentation has changed for the new wrapper version, however with not much. More details about that in the changelog section.

The old Test Harness Players will work ok with this new version of the wrapper, although a recompilation is needed, however a new very simple Test Player, in Flash this time, has been created to demonstrate the new features. The sources for this player are available in the downloads section too.

A sample has been added on the multiple instances post: Youtube AS3 Wrapper – Multiple instance sample

Hope you will enjoy this new version!

Youtube, Youtube Wrapper , , ,

Youtube AS3 Wrapper v0.7.2

June 3rd, 2009

A new version of Youtube AS3 Wrapper is available: v0.7.2

This new version fixes a bug where adding and removing the player to and from stage repeatedly causes it to crash.

The new version is available for download Youtube AS3 Wrapper – Downloads

Enjoy!

Youtube, Youtube Wrapper , , ,

Youtube AS3 Wrapper – Changelog

April 27th, 2009

Youtube AS3 Wrapper v0.8.0m

This new version introduces support for multiple videos playback in the same time, on the same stage!
Some changes in the api: All the methods have been added a new parameter, “playerid”, which will represent the id of the player to which the function will apply.
Example:

function loadVideo(id : String, startSeconds : Number = 0, playerid : uint = 0) : void;

The default for this parameter is 0, meaning that by default the function applies to the player with id=0. Which is the first player that is created.
If you use only one player (you don’t create more), you can forget about this parameter.

New methods added:

                 /**
         * Creates a new player
         * @return int the new player's id
         */

        function createPlayer() : int;
       
        /**
         * Sets the alpha [0,1] for the specified player
         */

        function setAlpha(alpha : Number, playerid : uint = 0) : void;
       
        /**
         * Sets the visibility for the specified player
         */

        function setVisible(visible : Boolean, playerid : uint = 0) : void;
       
        /**
         * Sets the position for the specified player
         */

        function setPosition(x : Number, y : Number, playerid : uint = 0) : void;
       
        /**
         * Swaps the depths of the 2 specified players
         */

        function swapDepths(playeridToBeSwapped : uint, playeridToSwapWith : uint) : void;
       
        /**
         * Brings the specified player to front
         */

        function bringToFront(playerid : uint) : void;
       
        /**
         * Sends the specified player to back
         */

        function sendToBack(playerid : uint) : void;
       
        /**
         * Sends the specified the specified player to it's original depth
         * Note that when usign swapDepths the player that is swapped has it's original depth set to the new depth
         */

        function sendToOriginalDepth(playerid : uint) : void;

The createPlayer method creates New player.
Always wait for the previous player the be ready before calling this method!
The method return the new player’s id. The first time the method is called, it will return 1. Because the player with id=0 is created without calling this method.
After calling this method, the PLAYER_READY event will be dispatched when the new player is ready, and event object will have the playerid parameter set to the new player’s id.

The other new methods speak for themselves through their names.

The YoutubeEvent has now a new parameter:

public var playerid : uint;

This parameter says now which player dispatched the event.

Youtube AS3 Wrapper v0.7.2

This new version fixes a bug where adding and removing the player to and from stage repeatedly causes it to crash.

Youtube AS3 Wrapper v0.7.1

Adds Adobe AIR support. The api remains unchanged.

Youtube AS3 Wrapper v0.7

Fixes the volume bug in IE and deprecates the reload():void and destroyAndReload():void methods because the volume works without reloading the player.

Youtube AS3 Wrapper v0.6

The first released version of the Youtube AS3 Wrapper.
Has problems with volume in Internet Explorer. In order to bypass this problem, the ytPlayer needs to be reloaded for every new clip that plays, using reload():void or destroyAndReload():void methods.

Youtube, Youtube Wrapper , , , ,

Youtube AS3 Wrapper v0.7.1

April 21st, 2009

A new version of Youtube AS3 Wrapper is available: v0.7.1

This new version adds Adobe AIR support.

The new version is available for download Youtube AS3 Wrapper – Downloads

Also, a new test harness player sources have been added, which makes use of the new wrapper and it’s AIR capabillities.
You can download the sources for the new Test Harness Player at the same link above.
Enjoy!

Actionscript 3.0, Youtube, Youtube Wrapper , ,

Youtube AS3 Wrapper – How to use

March 30th, 2009

This is a How to guideline on the Youtube AS3 Wrapper.

Before starting, this tutorial assumes you are at least familiar with AS3.

  • Firstly, you should download the latest Youtube AS3 Wrapper from here (the lastest at the time of this writing is v0.7). Unzip the contents into your project folder (generally the 2 swf file should be placed in the same directory as the swf file that will use the wrapper, or a subdirectory of it; in this tutorial I will assume they are in the same directory). Next, depending on whether you’re using the .as source files, found under pinosh/youtube/ in the zip archive, or the .swc component, located in the swc folder, you should place the 2 .as source files in the Classpath of your project, or include the .swc in the components directory.
    My Directory structure looks like this:
    • rootproject
      • classes
        • pinosh
          • youtube
            • IYoutube.as
            • YoutubeEvent.as
      • ytPlayer.swf
      • ytODLCWrapper.swf
      • TestPlayer.as
      • TestPlayer.swf
      • TestPlayer.fla

    With a directory like this, I should set the classPath to “./classes”.

  • Now TestPlayer.as will be set as the Document class in Flash. Since it’s going to be the Document class, we should make the TestPlayer class extend MovieClip.
    This is how our bare bones class should look at first:
    package {
    import flash.display.MovieClip;
        public class TestPlayer extends MovieClip {
            public function TestPlayer() {
                 super();
            }
        }
    }
  • Next, we will need IYoutube interface and YoutubeEvent class, so let’s import those:
        import pinosh.youtube.IYoutube;
        import pinosh.youtube.YoutubeEvent;

    Also, because we must load the ytPlayer.swf in our swf at runtime, we will need the Loader class and URLRequest class. Also we’ll need IOErrorEvent class and Event class to handle properly the events dispatched by our loader.

        import flash.events.Event;
        import flash.events.IOErrorEvent;
        import flash.display.Loader;
        import flash.net.URLRequest;
  • Now we have set up everything we need. So let’s load our youtube player. We’ll save our player, after it has been loaded, in a private variable named player.
    The code to load the player, will be placed inside the constructor of our TestPlayer class:
    var loader : Loader = new Loader();
    // listen for the right events
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.playerLoaded);
    loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, this.playerCannotBeLoaded);

    loader.load(new URLRequest("ytPlayer.swf")); // to pass the youtube api key use "ytPlayer.swf?apiKey="+apiKey

    Now we must declare and define the 2 event handler methods:

         private function playerLoaded(event : Event) : void {
                // grab the loader object
                var loader : Loader = event.target["loader"] as Loader;
                // add it to the display list of TestPlayer
                this.addChild(loader);
               
                // grab the IYoutube object; it's the content property of the loader object
                this.player = loader.content as IYoutube;
                // start listening for the events dispatched by player
                this.player.addEventListener(YoutubeEvent.PLAYER_READY, this.onYTPlayerReady);
                this.player.addEventListener(YoutubeEvent.PLAYER_STATE_CHANGE, this.onYTPlayerStateChange);
                this.player.addEventListener(YoutubeEvent.PLAYER_ERROR, this.onYTPlayerError);
         }

         private function playerCannotBeLoaded(event : IOErrorEvent) : void {
               // trace the for this test, bu should be handled more carrefully
               trace("Player Cannot be found: "+event);
         }
  • Now we’re only left with the youtube handler methods, and we should declare those.
         private function onYTPlayerReady(event : YoutubeEvent) : void {
                // now our player is ready to rumble; let's play a clip
                this.player.loadVideo("Lrmf283dSXw");
         }

         private function onYTPlayerStateChange(event : YoutubeEvent) : void {
                trace("TestPlayer::onYTPlayerStateChange ==> "+this.player.getPlayerState());
         }

         private function onYTPlayerError(event : YoutubeEvent) : void {
                trace("TestPlayer::onYTPlayerError ==> "+this.player.getPlayerError());
         }

So this is about everything to load the wrapper and play a first clip.

Here is how the entire class file should look like:

package {
import flash.display.MovieClip;
    import pinosh.youtube.IYoutube;
    import pinosh.youtube.YoutubeEvent;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.display.Loader;
    import flash.net.URLRequest;

    public class TestPlayer extends MovieClip {
        private var player : IYoutube;
        public function TestPlayer() {
             super();
             var loader : Loader = new Loader();
             // listen for the right events
             loader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.playerLoaded);
             loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, this.playerCannotBeLoaded);

             loader.load(new URLRequest("ytPlayer.swf")); // to pass the youtube api key use "ytPlayer.swf?apiKey="+apiKey
        }

        private function playerLoaded(event : Event) : void {
            // grab the loader object
            var loader : Loader = event.target["loader"] as Loader;
            // add it to the display list of TestPlayer
            this.addChild(loader);
           
            // grab the IYoutube object; it's the content property of the loader object
            this.player = loader.content as IYoutube;
            // start listening for the events dispatched by player
            this.player.addEventListener(YoutubeEvent.PLAYER_READY, this.onYTPlayerReady);
            this.player.addEventListener(YoutubeEvent.PLAYER_STATE_CHANGE, this.onYTPlayerStateChange);
            this.player.addEventListener(YoutubeEvent.PLAYER_ERROR, this.onYTPlayerError);
     }

     private function playerCannotBeLoaded(event : IOErrorEvent) : void {
           // trace the for this test, bu should be handled more carrefully
           trace("Player Cannot be found: "+event);
     }

     private function onYTPlayerReady(event : YoutubeEvent) : void {
            // now our player is ready to rumble; let's play a clip
            this.player.loadVideo("Lrmf283dSXw");
     }

     private function onYTPlayerStateChange(event : YoutubeEvent) : void {
            trace("TestPlayer::onYTPlayerStateChange ==> "+this.player.getPlayerState());
     }

     private function onYTPlayerError(event : YoutubeEvent) : void {
            trace("TestPlayer::onYTPlayerError ==> "+this.player.getPlayerError());
     }

   }
}

For the entire documentation and a list of all the methods you can use to manage youtube clips,
please check out the documentation: Youtube AS3 Wrapper – Documentation

When you test your app, make sure you don’t test in the Flash IDE as it will not work. Test it in browser or in standalone flash player!

This wrapper can be used with flex too, not only with flash. The Test Harness Player is a flex app. You can view the Test Harness Player here, and download the entire source for it here.

Youtube, Youtube Wrapper , , , ,

Youtube AS3 Wrapper v0.7

March 29th, 2009

A new version of Youtube AS3 Wrapper is available: v0.7

This new version fixes the volume and mute methods thus making the use of destroyAndReload method obsolete. This means you no longer have to destroy and reload the player in Internet Explorer.

The new version is available for download Youtube AS3 Wrapper – Downloads

Also, the test harness player has been update to use the new wrapper. The code that’s not needed, due to deprecation of destroyAndReload method, is commented out.
You can download the sources for the new Test Harness Player at the same link above.
Enjoy!

Youtube, Youtube Wrapper , , ,