Ahmed Nuaman


builder of internets ~ developer of dreams ~ tamer of Dachshunds

Loading HD Videos Through The YouTube Player API

Before I start, let me plug some of my code: a lot of developers out there go ahead and create their own little helper classes for the YouTube player. However, do feel free to use my “YouTube Approved” (oh yeah) Player API class up on github.

So, you’ve got your project and you’re told to “load that video in HD”. Now one must remember that unless your player is larger than, say 600px wide, there’s no point having it in HD. If you’re loading a HD video into a player that’s smaller than 600px, Flash Player is going to have to scale every frame down and this uses resources, and this isn’t good.

It’s worth having a good read of the playback quality types available from YouTube and decide which one works for your project.

So, back to the original dilemma, how does one make the player HD? Well, it’s pretty simple, just use the “setPlaybackQuality()” function, but this has to be fired, preferably, when the player has loaded and is buffering the video, like so:

private function foo():void
{
    player.addEventListener( 'onStateChange', handleStateChanged );
}

private function handleStateChanged(e:Object):void
{
    var state:Number = player.getPlayerState();
   
    if ( state === 3 )
    {
        player.setPlaybackQuality( 'large' );
    }
}

Simples eh? Like I said, all this is in my YouTube Player class up on github. Tell me what you think

Where have comments gone?

Good question my old fruity. I'm now sticking any post discussions on Google+. Why? Well simply it's better. WordPress's comment system isn't very elegant and nor are ones like Disqus or Livefyre, so to save hassle I've just shipped them off to a social network, like a real boss.

Search

My social skills

Latest blog posts

  • Loading posts...

Subscribe in a reader

Latest tweets

  • Loading tweets...