embed a YouTube video into your flash application

UPDATE: it seems that the web address assigned to the .flv file that y tube serves up is attached to your session id or something similar because after I ended the session by closing the browser window the url in the example is no longer valid – however the code works and stands as a proof of concept, of cause if anyone finds a work around please post it in the comments.

Every wanted to do dump the youTube player and embed the content right in to your flash homepage or flash application?

Na? me neither but I did run across some cool code in an English Web Design Mag and thought I’d try it out.

The video below is streaming – for now – form the youtube.com server, it’s the same video as my video clip of the week.

Here is the code, just create a new flash ActionScript 3 file and paste the code below into an empty keyframe, and heck your smart go figure out what to do with it ;)
var nc:NetConnection = new NetConnection();
nc.connect(null);

var ns:NetStream = new NetStream(nc);
var vid:Video = new Video(320,240);
this.addChild(vid);
vid.attachNetStream(ns);

ns.play("http://www.youtube.com/get_video?video_id=nRKIDdIaFyE&t=OEgsToPDskKpN-Xx5gZSrhfuCnISZPoy");

ns.addEventListener(NetStatusEvent.NET_STATUS, netstat);

function netstat(stats:NetStatusEvent){
trace(stats.info.code);
}
var netClient:Object = new Object();
netClient.onMetaData =function(meta:Object){
trace(meta.duration);
};
ns.client = netClient;