Displaying YouTube video images in Flash

So it’s been a while since I posted, but I haven’t really come across any problems that I couldn’t solve with a simple google search.  However, I recently came across an issue that took far too long to track down and fix, and it required more than a simple google search.  For a project I’ve been working on recently, part of it required me to load a still image preview from a given youtube url, and duplicate the image.  I had all sorts of cross domain policy file issues when attempting to duplicate the image because the crossdomain.xml policy file did not allow pixel-level image access, which meant I couldn’t duplicate the loaded images from the youtube.com url.

I needed the ability to duplicate the image so I wouldn’t have to load it over and over again.  After a lot of google search and trial and error, I finally found a youtube image url with a lenient cross domain policy file and thought I’d share it:

http://i.ytimg.com

You can verify it’s crossdomain.xml policy file by going to http://i.ytimg.com/crossdomain.xml.  The policy file allows for the duplication of the loaded image as a Bitmap object in flash.  If you want to load an image from there, simply create a URLRequest and point it to http://i.ytimg.com/vi/[videoId]/2.jpg, replacing [videoId] with the id of the youtube video found in the url to the video.  The 2 of the 2.jpg represents the size and image of the video image you want to load.

A more in-depth look into the numbering system reveals different numbers display different stills from the video at different sizes.  Here’s a breakdown of what I’ve found so far:

  • 0.jgp – 480×360 image.
  • 1.jpg – 130×97 image.  Different frame from 0.jpg
  • 2.jpg – 130×97 image.  Different frame from 1.jpg
  • 3.jpg – 130×97 image.  Different frame from 0.jpg and 1.jpg.

As a side note, passing in anything other than the above will load a generic 120×90 image, so you won’t get any load errors.  Thanks Google!

About Josh
Father of 3, programmer, husky owner, and a lover of geeky things. Find me on twitter @joshbjosh.

No Comments, Be The First!

Your email address will not be published.