bullet Displaying YouTube Content in AS3

Recently, while working on my portfolio, I was presented with the problem of displaying YouTube content extracted from an RSS feed in Flash. On the one hand there was the difficulty of parsing embed and object tags and extracting relevant data from the mess I was given, and on the other hand there was the problem of displaying the content itself.

YouTube provides documentation for their api, but after digging around online I was surprised to find that nobody had gone through with packaging it in a format I was willing to work with. There is an ActionScript 3 YouTube Wrapper available online, but it presumes that the Chromeless YouTube Player (http://www.youtube.com/apiplayer?version=3) you download to play videos with will be accessed using a combination of the static ExternalInterface class and external JavaScripts.

This seems, to me, to be unnecessarily complicated.

I’ve gone through the trouble of picking through the API and creating a simple class that loads a chromeless player and exposes methods you can use to manipulate it and display content from YouTube, without requiring any external javascript.

The application above is written in Actionscript 3. Basic usage is as follows:

import com.agitcraft.youtube.YouTube;
import com.agitcraft.youtube.YouTubeEvent;
_tube = new YouTube();
_tube.cueURL("http://www.youtube.com/v/-CsA1CcA4Z8", 0);
addChildAt(_tube, 0);

Each of the methods made available in the official YouTube API is available in some form or another via this set of classes. When I have a little more time I’ll follow up with official documentation and availability via google code.

Download AS3 YouTube Classes

Categories: APIDownloadsFlashUncategorized
Tags:
Published: 01.14.10 :: 6 Comments »
bullet Comments
Henery Schaffer said...

Hi there,

I looked over your blog and it looks really good. Do you ever do link exchanges on your blog roll? If you do, I’d like to exchange links with you.

Let me know if you’re interested.

Thanks..

Published: January 14, 2010 at 11:54 am
Ian Ford said...

Henery,

Thanks for the comment! While I am interested in link exchanges, I’m trying to restrict them to other blogs focusing on RIA development, the Flash platform, and graphic design.

Published: January 14, 2010 at 11:59 am
Absulit said...

It works thanks.
I found a funny issue in my project, I have to load the dinamyc sections inside another swf, but there is no stage because the flash security blah blah blah and then I can not addChild to the _tube, the video loads, I can hear the sound, but at the time to call addChild to add the _tube, the whole container dissapears… It is a weird issue inside my project, but I test the wrapper stand alone and it works!

that’s the story of my life :P

greetings

Published: March 19, 2010 at 12:49 am
Ian Ford said...

Absulit,

Glad to hear it’s working for you. I’m not sure what the specific resolution to the problem you’re having might be, but I would ask why you’re trying to add child elements directly to the YouTube instance.

The video container is provided by YouTube (they don’t allow any other implementation that I know of), so I can’t even comment on the contents of it.

I’d recommend keeping video controls (if that’s what you’re working on adding) separate from the YouTube instance.

Published: March 19, 2010 at 2:37 pm
Absulit said...

I think I said it wrong :P
I mean something like this

var _swf:*;
var _loader = new Loader()
_loader.load(new URLRequest(“my.swf”))
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);

function onComplete(e:Event){
_swf = _loader.content;
_swf.addChild(_tube)// here is the error
}

The code it’s simplified but is something like that. At the time it load, the _swf or _loader.content has no displaylist, so the entire container dissapears

addChild(_tube)

Published: March 27, 2010 at 10:24 pm
Ian Ford said...

Absulit,

Do you suppose it could be a masking conflict?

That is, in the code segment above, is the container “_swf” masked in any way? I would bet the chromeless youtube player uses masks, and I’ve personally run into trouble when trying to nest masked content.

Also, can you confirm after you’ve added _tube that it’s in the container? Maybe try this…

_tube.addEventListener(Event.ADDED_TO_STAGE, _someFunction, false, 0, true);

…and then confirm some of the other properties of the _tube.

Published: March 29, 2010 at 11:56 am
bullet Leave a Comment
Name

E-Mail Address

Website

Comment

Submit