Home > Flash and Actionscript, Macromedia Flex > Constructing YouTube FLV URL on client-side without any server-side script

Constructing YouTube FLV URL on client-side without any server-side script

It seems, there is a easier way of constructing YouTube! FLV URL on client-side without using any server-side script.

We need get the YouTube video_id from any of following places:-

Then, construct a URL like this: http://www.youtube.com/v/V3BsjxDZJM0

Above URL is used in YouTube embed-code. It is basically a server-side redirection that points to YouTube Player (.swf). Above redirects (server-side) to following URL:-
http://www.youtube.com/p.swf?video_id=V3BsjxDZJM0&eurl=&iurl=http%3A//sjc-
static12.sjc.youtube.com/vi/V3BsjxDZJM0/2.jpg&t=OEgsToPDskKzlTMEFZ1jOh40Xc3qOxzQ

As you can see in above URL, it contains “t” param (in red), which is what we need along with video_id to construct YouTube video (FLV) URL, YouTube FLV URL would look like this:-
http://www.youtube.com/get_video.php?video_id=V3BsjxDZJM0&
t=OEgsToPDskKzlTMEFZ1jOh40Xc3qOxzQ

You can check out code below to figure out things your own. You can also check out the example-app.

Flex 2.0/ActionScript 3.0 example:-


<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="onAppCreationComplete ()"
horizontalAlign="left"
width="800"
height="350">
<mx:Script>
<![CDATA[
import flash.net.*;
import flash.events.*;
import flash.display.*;
private var loader:Loader;
private var abortId:uint;
private function onAppCreationComplete ():void
{
loader = new Loader ();
}
private function startLoading ():void
{
var req:URLRequest = new URLRequest ("http://www.youtube.com/v/3IcwG0jUFxU");
loader.contentLoaderInfo.addEventListener(Event.INIT, handlerLoaderInit);
loader.load(req);
logMessage ("Loading YouTube URL..");
}
private function handlerLoaderInit (event:Event):void
{
logMessage ("Loaded, processing: " + loader.contentLoaderInfo.url);
var urlVars:URLVariables = new URLVariables ();
urlVars.decode (loader.contentLoaderInfo.url.split("?")[1]);
logMessage ("Processed:-");
logMessage ("\t\t video_id:" + urlVars.video_id);
logMessage ("\t\t t param:" + urlVars.t);
logMessage ("\t\t thumbnail-url:" + urlVars.iurl);
var flvURL:String = constructFLVURL (urlVars.video_id, urlVars.t);
logMessage ("YouTube FLV URL: " + flvURL);
playVideo (flvURL);
logMessage ("Started Playing Video...");
loader.unload();
}
private function constructFLVURL (video_id:String, t:String):String
{
var str:String = "http://www.youtube.com/get_video.php?";
str += "video_id=" + video_id;
str += "&t=" + t;
return str;
}
private function playVideo (url:String):void
{
player.source = url;
player.play();
}
private function logMessage (message:String):void
{
outputText.text += message + "\n";
trace (message);
}
]]>
</mx:Script>
<mx:HBox width="100%">
<mx:Label text="YouTube Video URL:"/>
<mx:TextInput id="urlText" width="300"/>
<mx:Button label="Submit" click="startLoading ()" id="submitButton"/>
</mx:HBox>
<mx:HBox width="100%">
<mx:VBox height="100%">
<mx:Label text="VideoDisplay:"/>
<mx:VideoDisplay width="320" height="240" id="player"/>
</mx:VBox>
<mx:VBox height="100%" width="100%">
<mx:Label text="Output:-"/>
<mx:TextArea id="outputText" width="100%" height="100%"/>
</mx:VBox>
</mx:HBox>
</mx:Application>

ActionScript 2.0 code-snippet:-


createEmptyMovieClip ("mc", getNextHighestDepth ());
var _mcl:MovieClipLoader = new MovieClipLoader ();
_mclListener = new Object ();
_mclListener.onLoadStart = function (target:MovieClip)
{
trace ("The URL is: " + target._url);
var _lv:LoadVars = new LoadVars ();
_lv.decode (target._url.split ("?")[1]);
trace ("t param: " + _lv.t);
trace ("video_id: " + _lv.video_id);
trace ("thumbnail: " + _lv.iurl);
trace ("flv url: " + constructFLVURL (_lv.video_id, _lv.t));
_mcl.unloadClip (target);
};
function constructFLVURL (videoId:String, t:String):String
{
var str:String = "http://www.youtube.com/get_video.php?";
str += "video_id=" + videoId;
str += "&t=" + t;
return str;
}
_mcl.addListener (_mclListener);
_mcl.loadClip ("http://www.youtube.com/v/3IcwG0jUFxU", mc);

 [1] Flash clients would require server-side proxy because YouTube changed crossdomain.xml sometimes back.

  • http://www.abdulqabiz.com/blog Abdul Qabiz

    @benjamin: That’s done and thats what you can achieve if you look at the examples on this blog or web… Using different techniques allows you to load, stop, play, rewind etc YouTube videos….
    @Nicoweb: That looks neat, thanks for it..
    -abdul

  • http://www.grindstonemedia.net ryan

    thanks dude….
    i’ve been looking for this. its sad that such a popular service like youtube has an api that is surrounded by so many hacks… i think they should open up the api a bit more.
    p34c3

  • Iulian

    Hi everyone,
    I’ve made a player using FLVPlayback component from Flash 8.0 and I don’t understand why it does work on Firefox and it doesn’t on IE6 and IE7. Could anyone help me? Thanks a lot…
    Iulian

  • http://www.braingiants.com Evian

    I must be missing something really obvious. A few folks have mentioned this already, but I haven’t seen a concrete answer.

    Using the AS2 code works just fine for downloading the flv, but not when you try and send it to the FLVPlayback using the contentpath.

    I used:
    FLVPlayback.contentPath = constructFLVURL (_lv.video_id, _lv.t);
    which produces a 1005 Error claiming it must have the .flv extension.

    Can anyone shed some light on this for me?

  • http://www.braingiants.com Evian

    I must be missing something obvious here. When using the AS2 version it works fine, but when I use the constructFLVURL function for the contentPath,I get the 1005: Error which states that I need the .flv extension. Am I the only one with this error? Copying that same string into a browser prompts me to download so I know it isn’t the string. Thanks for any help, this will absolutely revolutionize my current project!

  • Hendra

    Hi,
    Can I have the source for your YouTubeClientSideDemoFlex.swf file?

  • http://www.abdulqabiz.com/blog Abdul Qabiz

    @Evian: FLVPlayback checks for flv extension, there is some issue with it. I would check for a workaround…It’s weird that FLVPlayback missed a use-case like this, in web-application we do use redirects and not always depends on file-extension…
    @Hendra:- The first code snippet in above post is the source-code of YouTubeClientSideDemoFlex.swf…
    -abdul

  • http://www.meandmybadself.com Jeffery

    Is the php script on Youtube’s side no longer working? It’s returning a 410 Gone code, which tells me that it’s a permanent move on their part.
    Which, sorta brings us back to square one. How are the players deriving the subdomain that the .flv is coming from?

  • http://www.abdulqabiz.com/blog/ Abdul Qabiz

    @Jeffery: I just checked it works, it might not be working for some video_ids?
    -abdul

  • Rabi

    Thanks for wonderful into. I do have a question. I have been using video player that uses, component FLVPlayBack that came with Flash8. How do I supply the youtube path to this component? It asks for contentPath which should be a flv file. Any suggestions would be great. Thanks again.

  • http://www.meandmybadself.com Jeffery

    Ah. I see the issue.
    Youtube changed the FlashVar format to a string keyed object. It used to be provided via the url query string.
    var swfArgs = {hl:’en’,video_id:’IZfIFzBsDsU’,l:’69′,t:’OEgsToPDskIIJps_QOHBWRlp-jl8Z66t’,sk:’2OO-1MpUsGx0EJkFDrt7SQU’};
    Apologies for the formatting.
    So, I’m using a PHP regular expression to snag it:
    preg_match(‘/var swfArgs = {hl:\’([^\']+)\’,video_id:\’([^\']+)\’,l:\’([^\']+)\’,t:\’([^\']+)\’,sk:\’([^\']+)\’};/’, $page, $regs);
    $pass_to_getvideo = $regs[2].”&hl=”.$regs[1].”&l=”.$regs[3].”&t=”.$regs[4].”&sk=”.$regs[5];

  • Rabi

    Use http://cache.googlevideo.com/get_video?video_id=ffMSy8usAlc&.flv
    where “ffMSy8usAlc” is the youtube id
    Works with FLVPlayback component in Flash 8.

  • Evian

    Has anyone else gotten what Rabi suggested to work?

    I still get a 1005 Error.

    “1005: Invalid xml: URL: “http://cache.googlevideo.com/get_video?video_id=JHUuqsSCn5g&.flv&FLVPlaybackVersion=1.0.1″ No root node found; if url is for an flv it must have .flv extension and take no parameters”

    What is really weird is it auto adds “&FLVPlaybackVersion=1.0.1″ to my URL, I didn’t add that.

    Let me know if anyone has found a work around for the FLVPlayback component in Flash 8.
    evian.

  • http://www.coffeetwitter.com Bertelle Nicolas

    Hi everyone,
    next to a work on youtube, i saw that Google add a new type of API that make the old one deprecated.
    It may explain the problem encoutered by one of you in the comments below.
    Enjoy sharing and looking videos on youtube ;-)

  • http://xtoned.com/log shanX

    @Nicoweb: You made me lazy, anyway Thanks :)

  • http://www.myspace.com/mrgrind334 Calvin

    Im trying to figure out how to get my videos to autoplay on You tube… for example…I know the code &autoplay=1
    But it does work on Myspace but it doesnt work on Youtube….I want my video to play when someone views my Channel….Please help….

  • http://www.e-consystems.com Ram Prasath

    Hi,
    i am ram prasath.i am created an flash file to play youtube videos using action script 3.
    The following error was return in my console

    VideoError: 1005: Invalid xml: URL: “http://www.youtube.com/get_video.php?video_id=3IcwG0jUFxU&t=OEgsToPDskK-JSXCoECKg-4KUiDLgOps&FLVPlaybackVersion=2.0″ No root node found; if url is for an flv it must have .flv extension and take no parameters
    at fl.video::SMILManager/http://www.adobe.com/2007/flash/flvplayback/internal::xmlLoadEventHandler()
    at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/flash.net:URLLoader::onComplete()

    i mentioned the full flash script below

    Plz provide some solution for me.I am trying this flash to play in local network not even in html file.

    import flash.events.Event;

    import fl.events.ComponentEvent;

    import fl.events.ColorPickerEvent;

    import fl.controls.RadioButtonGroup;

    import fl.containers.UILoader;

    import flash.net.NetConnection;

    import flash.net.NetStream;

    import fl.video.*;

    import flash.net.*;

    mport flash.display.*;

    var loader:Loader;

    var rbGrp:RadioButtonGroup = RadioButtonGroup.getGroup(“fontRbGrp”);

    rbGrp.addEventListener(MouseEvent.CLICK, rbHandler);

    txtCp.addEventListener(ColorPickerEvent.CHANGE,cpHandler);

    msgCb.addEventListener(Event.CHANGE, cbHandler);

    var tf:TextFormat = new TextFormat();

    onAppCreationComplete();

    function rbHandler(event:MouseEvent):

    void {
    switch(event.target.selection.name) {
    case “smallRb”:
    tf.size = 14;
    break;
    case “largerRb”:
    tf.size = 18;
    break;
    case “largestRb”:
    tf.size = 24;
    break;
    }
    trace(event.target.selection.name);

    aTa.setStyle(“textFormat”, tf);
    }

    function cpHandler(event:ColorPickerEvent):void

    {
    tf.color = event.target.selectedColor;
    aTa.setStyle(“textFormat”, tf);
    }

    function cbHandler(event:Event):void {
    aTa.text = event.target.selectedItem.label;
    }

    function onAppCreationComplete ():void
    {
    trace(“Executed on load”);

    loader = new Loader ();

    var req:URLRequest = new URLRequest (“http://www.youtube.com/v/3IcwG0jUFxU”);

    loader.contentLoaderInfo.addEventListener(Event.INIT, handlerLoaderInit);

    loader.load(req);

    logMessage (“Loading YouTube URL..”);
    }

    function logMessage (message:String):void

    {
    //outputText.text += message + “\n”;
    trace (message);
    }

    function handlerLoaderInit (event:Event):void

    {
    logMessage (“Loaded, processing: ” + loader.contentLoaderInfo.url);

    var urlVars:URLVariables = new URLVariables ();

    urlVars.decode (loader.contentLoaderInfo.url.split(“?”)[1]);

    logMessage (“Processed:-”);
    logMessage (“\t\t video_id:” + urlVars.video_id);

    logMessage (“\t\t t param:” + urlVars.t);
    logMessage (“\t\t thumbnail-url:” + urlVars.iurl);

    var flvURL:String = constructFLVURL(urlVars.video_id, urlVars.t);

    logMessage (“YouTube FLV URL: ” + flvURL);

    var my_FLVPlybk = new FLVPlayback();

    my_FLVPlybk.x = 79;
    my_FLVPlybk.y = 130;
    my_FLVPlybk.bufferTime = 0.1;

    addChild(my_FLVPlybk);

    my_FLVPlybk.skin = “file:///c|/Program Files/Adobe/Adobe Flash CS3/en/Configuration/FLVPlayback Skins/ActionScript 3.0/SkinOverPlaySeekMute.swf”;
    my_FLVPlybk.source = flvURL;

    my_FLVPlybk.play();
    logMessage (“Started Playing Video…”);

    loader.unload();

    }

    function constructFLVURL (video_id:String, t:String):String
    {

    var str:String = “http://www.youtube.com/get_video.php?”;
    str += “video_id=” + video_id;
    str += “&t=” + t;
    return str;
    }

  • Pritam

    Dear Abdul,
    I am creating Video Player using SWFLoader in Flex. I want to load the different videos on clicking of each button. For any first click of button it starts playing video from youtube or google video but as soon as i click on other button for different video it goes in the loading mode and i am not able to see the video. Alos on local my swfLoader size is correct but as soon as i upload on the we server it height and width becomes very large. See my Code below-

  • Ben

    @Pritam
    I am experiencing similar problems in as2.
    I can load one video into a player, but subsequent videos constantly buffer, and never load. I’m stumped as to why this could be.
    I suspect your problem with resizing is one I have already over come. In AS2 I set an onLoadInit handler to resize once the movie is loaded. I’m not familiar with flex, but I imagine you could put the resize in the onImageLoaded listener instead.

  • clayton

    I don’t see how the AS2 code posted above could possibly work. The URL is:
    http://www.youtube.com/v/3IcwG0jUFxU
    The code relies on the fact that the following line splits the url into its various pieces:
    _lv.decode (target._url.split (“?”)[1]);
    However, there is no ‘?’ in the url, so the above code will return undefined. All subsequent properties will return undefined as a result.

  • http://flashwizard.elementfx.com Arun Lal

    @Clayton
    when the given link;
    it is redirected to the link as mentioned below;
    http://www.youtube.com/swf/l.swf?video_id=3IcwG0jUFxU&eurl=&iurl=http%3A//img.youtube.com/vi/3IcwG0jUFxU/default.jpg&t=OEgsToPDskK8DWRmRDamYAyrq0qe43vu&rel=1&border=0
    which of course, consists ‘?’ ;
    this procedure is basically done to get the ‘t’ value from the link which in this case is
    I hope now its clear to you;
    Thanks to Abdul for this brilliant crack;
    Regards

  • dEPUTsTERONE

    Hello guys,
    The FLVPlayback-component isn’t able to play the parsed files within flash 9.
    I’m searching for a workaround for 2 days now and I’m really helpless…
    How can I force the FLVPlayback to load such a file:
    http://gdata.youtube.com/feeds/api/videos/Zo52T7uKOJU/related
    Regards

  • http://www.sks.kr.ua zulin

    You can use MediaDisplay (or MediaPlayback) component to avoid “VideoError: 1005″.

  • Lijo

    I dont know how to do it can someone mail it to me with this video OS3eBdJczn8

  • http://na Susan

    Thanks for this awesome work.
    One question I have is — once we’ve constructed an FLV url, I notice that YouTube returns something different, each time the script is run.
    However, the previous url works, at least a few seconds later.
    Do the FLV urls stop working? i.e. do we need to call it again, for the same video, every time we want to use it? or can we save the constructed flv url and reuse it each time we want the youtube video?

  • http://www.abdulqabiz.com/blog/ Abdul Qabiz

    @Susan:-
    > YouTube returns something different
    >, each time the script is run.
    Yup! It returns the closes or available server
    > Do the FLV urls stop working?
    Not sure of that..
    > Do the FLV urls stop working?
    > i.e. do we need to call it
    > again, for the same video,
    > every time we want to use it?
    > or can we save the constructed
    > flv url and reuse it each time
    > we want the youtube video?
    You can do either of these. Call the code everytime to get the URL or save the URL (returned) and used it later… Latter one might be faster, if your users are in same geography (like USA or Europe etc). If you have users from all over the world, you might want to use former approach (get URL everytime)..
    BTW! Did you check out my other posts of YouTube FLV path using server-side tricks?
    -abdul

  • http://youtubexml.com sam
  • Rohit

    Hi Abdul, I am able to construct video url but I am unable to find a way to play a video on cross-domain context.

  • http://www.abdulqabiz.com/blog Abdul Qabiz

    @Rohit: FLV should play and there is no crossdomain.xml required for playing flv files, it might be required when you want to capture the bitmap…
    Check this out:-
    1) Go to http://www.abdulqabiz.com/temp/flvPlayer.swf
    2) Paste this url: http://youtube.com/get_video?video_id=gttvfPjLV1I&t=OEgsToPDskLQpM1nn8G0f6lVIRXvmeag
    It works fine..
    -abdul

  • Washiki

    Hey Abdul,
    I am trying to use your AS2 code as part of my player. I keep getting the security sandbox violation, though.

    I tried adding System.security.allowDomain (“youtube.com”) at the beginning of the actionscript code but it still pops up. Also, would you know what/where I’d put the code to autoplay?

    Here’s my code. I’ve only started learning actionscript since I started streaming videos so I do not know too much. Perhaps you have any suggestions to make it more efficient, too? I’m just chopping up codes until it works :P

    System.security.allowDomain (“youtube.com”)
    createEmptyMovieClip (“mc”, getNextHighestDepth ());
    var _mcl:MovieClipLoader = new MovieClipLoader ();
    _mcl.addListener (_mclListener);
    _mcl.loadClip (“http://www.youtube.com/v/oqNMx_1jmlU”, mc);
    _mclListener = new Object ();
    _mclListener.onLoadStart = function (target:MovieClip)
    {
    var _lv:LoadVars = new LoadVars ();
    _lv.decode (target._url.split (“?”)[1]);
    _mcl.unloadClip (target);

    var connection_nc:NetConnection = new NetConnection();
    connection_nc.connect(null);
    var stream_ns:NetStream = new NetStream(connection_nc);
    my_video.attachVideo(stream_ns);
    stream_ns.play(“http://www.youtube.com/get_video.php?video_id=” + _lv.video_id + “&t=” + _lv.t);
    stream_ns.setBufferTime(15);
    };

  • crucifix

    Thank you very much… This is very useful.

  • http://ciao lorena

    vorrei mettere dei video su yutube

  • Andy

    >Flash clients would require server-side proxy
    Abdul,
    But your example code in Flex AS3 seems to go to YouTube directly! How does this work?

  • http://www.nivonova.com Robin Casey

    Don’t know for sure how off-topic this is, but if you get into some errors, like 100;
    try to handle your php/asp flv source in flash like:
    your-folder/whatever/stream.php/anything-here.flv

  • http://www.abdulqabiz.com/blog Abdul Qabiz

    @Andy: My example in AS3 is not using YouTube RSS feed or API. Both of those operations are crossdomain data loaoding operations and require either a liberal crossdomain.xml on youtube.com or proxy on your server…
    What I am doing above is a hack to get the “t” param and then construct flv url from that. I am not sure, this hack still works, I need to spend sometime updating all my posts/code related to youtube.
    @Robin: Never encountered that error, but thanks for the update.
    -abdul

  • Andy

    Abdul, thanks for your reply. I actually didn’t realize that when the docs said “Flash can’t load data from another domain without the crossdomain.xml file” that did not include things like reading the FLV file. Thanks for clearing that up.
    I’ve been trying to get the FLVPlayback control that comes with Flash to use the youtube URL, but for whatever reason it doesn’t seem to work. Does it expect an url with a FLV extension or something? Any idea?
    Thanks.
    Great blog. Very helpful.
    -Andy

  • http://www.abdulqabiz.com/blog Abdul Qabiz

    @Andy: FLVPlayback has hardcoded logic for file-extension, it looks for .flv in the end. I have seen people finding out workaround for that..Please read above comments or search, I am sure it has been solved..
    Did you try appending &.flv in the end of URL, see if it works?
    -abdul

  • Danny

    Nice cript, but do you know how to make a video preload?
    thanks

  • http://www.buttonpresser.com Pete

    can you make the YouTubeClientSideDemoFlex.fla available? I’m a newbie

  • http://www.abdulqabiz.com/blog Abdul Qabiz

    @Pete: There is no .fla file for that code, it’s a flex app, and code is there in my post above (the first code box)…
    Sorry, you have to wait and post the comment again..
    -abdul

  • Peter

    Hey Abdul,
    I’ve having some issues with AS3 (not Flex) and loading .flv from youtube using your technique.
    I can get your technique to work for grabbing the URL but when I tried to play it in the FLVPlayback component I get a security sandbox violation as below:
    *** Security Sandbox Violation ***
    Connection to http://www.youtube.com/get_video.php?video_id=eBGIQ7ZuuiU&t=OEgsToPDskIQtQo0D-3opVzh3CDEzbwl&FLVPlaybackVersion=2.0 halted – not permitted from http://www.gemtowerdefense.com/test.swf
    Now, your example http://www.abdulqabiz.com/temp/flvPlayer.swf works for the URLs I grab, is that example a Flex app or an AS2 app or an AS3 app?

  • http://www.abdulqabiz.com/blog Abdul Qabiz

    @Peter: That’s a flex app, I would investigate why it’s not working for you.
    Thanks for feedback.
    -abdul

  • mike

    This code works just fine. Can I ask how do you now send this video as an email?
    Thanks,
    Mike

  • http://vivoenguatemala.wordpress.com Jacob

    Hi Abdul, I’ve made everythig, I understand that the as2 is for retrieving the flv file but it only works for a download as any other online tools. I tried the app en Flex and obviously works fine too, but how can I play the flv in flash? I’m driving crazy trying to I know how to do that with a static flv address, but I really don’t find the way to make it using the string URL. tks.

  • jake

    thank you for that hint!
    the link to the .flv is all i need.

  • sx

    I didn’t use your script code, but it’s similar and when I unload a YouTube video and then then load a different one, the one that was playing before it loads and plays instead of the new one. what could be the problem? and may I ask for the actual FLA file for your example if it isn’t too much of a trouble?? thanks.

  • http://abowman.com adam bowman

    Thanks for posting this.
    Can you please update the original AS2 code so that is uses onLoadInit rather than onLoadStart?
    onLoadStart does not work in IE.
    That will save others a lot of time troubleshooting and will make this page more popular.
    Thanks

  • nick

    I’m a complete noob so forgive me for asking this.
    I’d like to able to play this video: http://youtube.com/watch?v=gYo2XlgL8pQ
    When I enter the altered url http://youtube.com/v/gYo2XlgL8pQ in the test application the video is played.
    I however don’t understand how I can get this to work on my site, what do I need to put in my html ?
    any help is greatly appreciated

  • http://www.instacoll.com Anthony

    This is the class which I created using Flash CS3 (Action script 3.0)using Abdul’s techniques for playing youtube video . I am posting it coz it might be useful for somebody . it plays hard a movie from this url “http://www.youtube.com/watch?v=KmrdWpXSnoo&feature=related” which is hard coded
    package{
    import flash.display.Sprite;
    import flash.display.MovieClip;
    import flash.net.*;
    import flash.media.Video;
    import flash.events.*;
    import flash.display.Loader;
    import flash.system.*;
    public class VideoTest extends Sprite
    {
    private var vidLoader:Loader;
    private var flvURL:String;
    private var videoID:String;
    private var vidRequest:URLRequest;
    public function VideoTest()
    {
    flash.system.Security.allowDomain(“http://www.youtube.com”);
    flash.system.Security.loadPolicyFile(“http://www.youtube.com/crossdomain.xml”);
    var vidURL:String = normalizeURL(“http://www.youtube.com/watch?v=KmrdWpXSnoo&feature=related”);
    var vidRequest:URLRequest = new URLRequest(vidURL);
    vidLoader = new Loader();
    vidLoader.contentLoaderInfo.addEventListener(Event.INIT, onVidRequestLoad);
    vidLoader.load(vidRequest);
    }
    private function onVidRequestLoad(evt:Event):void
    {
    trace(“in onVidRequestLoad”);
    var vars:URLVariables = new URLVariables();
    vars.decode(vidLoader.contentLoaderInfo.url.split(“?”)[1]);
    videoID = vars.video_id;
    flvURL = constructFLVURL(vars.video_id, vars.t);
    trace(flvURL);
    trace(“out onVidRequestLoad”);
    var nc:NetConnection = new NetConnection();
    nc.connect(null);
    var ns:NetStream = new NetStream(nc);
    ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
    ns.play(flvURL);
    function asyncErrorHandler(event:AsyncErrorEvent):void
    {
    trace(“error”);
    }
    var vid:Video = new Video();
    vid.attachNetStream(ns);
    addChild(vid);
    }
    private function constructFLVURL(video_id:String, t:String):String
    {
    var tmp:String = “http://www.youtube.com/get_video.php?”;
    tmp += “video_id=”+video_id;
    tmp += “&t=”+t;
    return tmp;
    }
    private function normalizeURL(URL:String):String
    {
    var tmp:String = URL;
    tmp = tmp.split(“watch?v=”).join(“v/”);
    return tmp;
    }
    }
    }

  • artur

    Your example is NOT WORKING:
    http://www.abdulqabiz.com/files/YouTube_Client_side_demo/YouTubeClientSideDemoFlex.html
    im not able to see any video play..
    although it says:
    Loading YouTube URL..
    Loaded, processing: http://www.youtube.com/swf/l.swf?video_id=3IcwG0jUFxU&rel=1&eurl=&iurl=http%3A//i.ytimg.com/vi/3IcwG0jUFxU/default.jpg&t=OEgsToPDskK1bXmTe-60W17V4INmB6YC
    Processed:- video_id:3IcwG0jUFxUt param:OEgsToPDskK1bXmTe-60W17V4INmB6YC
    thumbnail-url:http://i.ytimg.com/vi/3IcwG0jUFxU/default.jpg
    YouTube FLV URL: http://www.youtube.com/get_video.php?video_id=3IcwG0jUFxU&t=OEgsToPDskK1bXmTe-60W17V4INmB6YC
    Started Playing Video…
    im using FFox , and the latest flashplayer 9
    does this error have to do with the new CrossDomain policy?
    i would like to know if its possible to build a our own flex 3 video player..that feeds from YouTube… is that possible now with their new API?
    thanks.. artur