-
Website
http://www.abdulqabiz.com/blog/ -
Original page
http://www.abdulqabiz.com/blog/archives/2007/04/02/constructing-youtube-flv-url-on-client-side-without-any-server-side-script/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
melanie12345
1 comment · 1 points
-
kanti
1 comment · 1 points
-
anuradhashinde2001
2 comments · 2 points
-
joeboxer
1 comment · 1 points
-
petkusj
2 comments · 1 points
-
-
Popular Threads
is it possible to run AS2 code with video playback component : myVideoPlayback.contentPath = constructFLVURL (_lv.video_id, _lv.t)?
simply brilliant, but can´t be done a function that does everything with one?
I have modified this so that she takes "target" but, since everything could be made simultaneously?
createEmptyMovieClip ("mc", getNextHighestDepth ());
var _mcl:MovieClipLoader = new MovieClipLoader ();
_mclListener = new Object ();
_mcl.addListener (_mclListener);
_mcl.loadClip ("http://www.youtube.com/v/3IcwG0jUFxU", mc);
_mclListener.onLoadStart = function (target:MovieClip){
trace ("flv url: " + constructFLVURL (target));
salida = "oeeeoeoeoeoe: " + constructFLVURL (target);
_mcl.unloadClip (target);
};
//My Modification
function constructFLVURL (dir):String {
var _lv:LoadVars = new LoadVars ();
_lv.decode (dir._url.split ("?")[1]);
trace ("The URL is: " + target._url);
trace ("t param: " + _lv.t);
trace ("video_id: " + _lv.video_id);
trace ("thumbnail: " + _lv.iurl);
var str:String = "http://www.youtube.com/get_video.php?" + "video_id=" + _lv.videoId + "&t;=" + _lv.t;
return str;
}
Also, could you post the source so I (and possible other people) can see how you did it?
Thanks.
..k..
You can see the working example: http://www.abdulqabiz.com/files/YouTube_Client_...
Source for this example is already in this page, check out the post above.
@Kyle: You don't need a php-proxy if you use the approach mentioned in this post. You can see a working AS2 example here:
http://www.abdulqabiz.com/files/YouTube_Client_...
Fla file: http://www.abdulqabiz.com/files/YouTube_Client_...
Hope that helps...
-abdul
The example you posted above (youtube_flv_url_test_as2.*) both return 'undefined' (for the parameters) to me when I run it, no matter if I run it from your website, my harddisk or localhost.
Might be just me that I don't understand the concept though, but I'd be happy when it works here :)
Thanks, I just noticed it doesn't work for IE for some reason.. I would check it out..
I am running it FireFox 2.x and it works fine for me... I think, it should work for you also..
I got confirmation from a friend that it works for her also..
Thanks
-abdul
Thanks for responding :) I can confirm that it DOES work in FireFox 2.x as well as Opera 9. Here's a screenshot of all 3 browsers.
I ended up using a php proxy, but only because my project required the use of Zinc, which forces you to use IE as the default web browser engine... which has the problems mentioned above.
Best,
..k..
So it seems YouTube will provide the video id and 't' code for videos when requesting by tag (REST api), but they don't have an api call one can use to simply convert a youtube video url, to flv stream url? Seems like that would help everyone out of hacking around (coupled with a reasonable terms of use perhaps)...
In my particular use case, I wouldn't mind embedding YouTube's stock player, however there is no reliable way (it seems) in Flash to pull the plug on YouTube's NetStream instance. e.g. after embedding their player inside another SWF - when it comes time to unloadClip/removeMovieClip, the audio stream continues. So I'm stuck rendering the flv directly as others are doing on this thread.
var soundController:Sound = new Sound();
soundController.stop();
(http://www.adobe.com/cfusion/knowledgebase/inde...)
And when using a straight loadMovie, the Sound object does in fact stop playing stream, but within Firefox (MAC at least), attempting to replay the same exact video again in the same session is problematic -- the video, (even upon restarting Firefox) refuses to stream, and will only play again after fully downloading.
Nothing can ever be simple these days (nor bug free).
If you have any suggestions feel free to drop me a message on my blog and I'll get back to you. Otherwise, apologies for the off topic digression.
and is it your YouTubeClientSideDemoFlex is done by flash cs3 or flash 8
*** Security Sandbox Violation ***
SecurityDomain 'http://www.youtube.com/p.swf?video_id=3IcwG0jUFxU&eurl;=http%3A//www.youtube.com/v/3IcwG0jUFxU&iurl;=http%3A//img.youtube.com/vi/3IcwG0jUFxU/2.jpg&t;=OEgsToPDskJRMVlkIy0HLHFpn8x3JaKu' tried to access incompatible context 'file:///C|/Users/AnDY/Desktop/youtube%5Fflv%5Furl%5Ftest%5Fas2.swf'
Thanks for your AS2 code, I was finally able to get it working displaying Youtube videos. Muchos Gracias! (Using Firefox 1.5.0.11 on XP for those whom stated had trouble)
I did have a question though. How difficult would it be to modify this AS2 code to stream other video flv like Revver, Bliptv, and maybe eventually Joost etc.?
Thanks for your AS2 code, I was finally able to get it working displaying Youtube videos. Muchos Gracias! (Using Firefox 1.5.0.11 on XP for those whom stated had trouble)
I did have a question though. How difficult would it be to modify this AS2 code to stream other video flv like Revver, Bliptv, and maybe eventually Joost etc.?
> it be to modify this AS2 code to stream other
> video flv like Revver, Bliptv, and maybe
> eventually Joost etc.?
Revver and BlipTV can be played using AS2 code, you would need to write the logic. You can use Revver API or BlipTV's RSS feed to do that...
-abdul
testing your code for loading flv from youtube, i got stupid and created an iteration of part of the process, and was able to give one of my youtube videos viewership of 20,000+. It won an honor for most viewed in a 24 hr period.
Then I gave another video 5,000+ hits. Unfortunately for me, i was logged into youtube at the time and as a result my profile now has me as having viewed 5,000+ videos. now im apprehensive because i dont want google to contact me or, worse, remove the ability to access the t parameter! crime does not pay and let that be a lesson to the kids out there, seriously.
anyway my real vocation, the one with a future, is to build an RIA video player able to integrate videos from youtube, google video, blinkx, brightcove, and, not least, locally hosted, etc. into the same playlist(s).
abdul, serious serious thanks because your blog and the concepts you expose in it have been instrumental in my development of this product. pure brilliance.
Regards,
Doon Rothmani
how did you get by this sandbox violation problem.
i get the same error
cheers
uri
I am sure, youtube player doesn't have anything that can cause any damage to your swf, if you do that :)
@DoonRothmani:
> anyway my real vocation, the one with a future,
> is to build an RIA video player able to
> integrate videos from youtube, google video,
> blinkx, brightcove, and, not least, locally
> hosted, etc. into the same playlist(s).
You can look at the Media RSS standard and do it. We are doing it in Mixercast.com, where you can pull videos from different sources (youtube, google-video, metacafe, digitalmotion, blip.tv etc).
There are sites which don't provide FLV path which you can find through workaround (like in Youtube case), though I feel these sites can atleast provide preview (shorter length) flv files so I posted something about it here:-
http://www.abdulqabiz.com/blog/archives/general...
> abdul, serious serious thanks because your blog
> and the concepts you expose in it have been
> instrumental in my development of this product.
> pure brilliance.
Glad to know, I could be of some help... Thanks for reading my blog and giving feedback.
@Corey: Did you find the solution for your problems? Unfortunately, you can not control things inside YouTube player because of crossdomain scripting... Why don't you create your own player to play YouTube videos? You would have more control?
Thanks
-abdul
If I am correct, this code is being used for sites like Mixercast.com.
And how does Mixercast stream video from other sites like Brightcove Bip.tv is it with this same code?
> Is there any truth to what Doon Rothmani is saying
> about this being a violation of some sort?
I don't know about violation but we are surely doing things using workaround. YouTube! doesn't give you URL and we are doing working arounds..
In case of Doon Rothmani, he gamed the system to be among top videos, though I had never thought someone can use my script that way...
> If I am correct, this code is being used for
> sites like Mixercast.com.
Kind of..
> And how does Mixercast stream video from other
> sites like Brightcove Bip.tv is it with this
> same code?
Blip.tv gives you Media RSS (an API also), they also give the URL for flash-videos (flv), so it's easy. Brightcove doesn't give video-path, so it's tricky to use their videos, infact they have kind of tight DRM thingy in there...
-abdul
PS: I have been surfing online for 2 days and your project is the only one i found that could really help me.
You need to enter the URL in this format:-
http://www.youtube.com/v/
Example:-
http://www.youtube.com//v/b2oegRiaA_0
That should work fine..
-abdul
Help from anyone will be appreciated.
Thanks again
Any help would be much appreciated.
I tried to insert the url into an embed flash script but I am clearly missing something.
This is a great demonstration btw, and any help would be appreciated.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:button label="Play" click="vp.play()" right="70" top="10"/>
<mx:button label="Stop" click="vp.stop()" right="10" top="10"/>
<mx:TextInput
id="inputURL"
text="http://server/file.flv" left="10" right="129" top="10"/>
<mx:VideoDisplay
id="vp"
autoPlay="true"
source="{ inputURL.text }" left="10" right="10" top="39" bottom="10"/>
</mx:Application>
and when i press run,it says i got errors in the code for building stop and play buttons:
<mx:button label="Play" click="vp.play()" right="70" top="10"/>
<mx:button label="Stop" click="vp.stop()" right="10" top="10"/>
Anyone help about how to add 2 buttons for playing and stopping the video?
Thanks
Zoran
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:button label="Play" click="vp.play ()"/>
<mx:button label="Stop" click="vp.stop ()"/>
<mx:TextInput
id="inputURL"
text="http://server/file.flv" left="10" right="129" top="10"/>
<mx:VideoDisplay
id="vp"
autoPlay="true"
source="{ inputURL.text }" left="10" right="10" top="39" bottom="10"/>
</mx:Application>
Hope that helps..
-abdul
Cheers..
BTW! Check out another post of mine, where you don't need "t" param.
http://www.abdulqabiz.com/blog/archives/general...
Since when do students request "the complete source code" for a project? I though students were given projects to learn how to do things THEMSELVES. things must have changed dramatically since i got my comp sci. degree!
If I were you (which I am not, and I realize this) I would tell this type of poster to quite frankly bug off.
Any one who is a student and can't even debug a typo in his code does not deserve to have a project handed to him, much less graduate with a degree in computer technology. He will only grow to be a parasite producing nothing for himself and grabbing credit from others.
People who can't write (or debug) their own code or who are too lazy to do so, should be doing something else with their time.
just my humble opinion. sorry, but reading some of these posts really peed me off.
doon
Could you give me a further point in the right direction as to getting Revver to play like your youtube code.
Just wanting to take advantage of the higher quality videos from sites like Revver. Thanks!
Could you give pointers to convert your as3 code to equivalent perl code?
Regards,
Neha
-abdul
and it will work in IE
private function startLoading ():void {
var excludeLink:String = "http://www.youtube.com/watch?v=";
var lngExclude:Number = excludeLink.length;
var lngLength:Number = urlText.text.length;
var txtYouTubeLink:String = urlText.text.slice(lngExclude,lngLength);
var youTubeLink:String = "http://www.youtube.com/v/" + txtYouTubeLink;
var req:URLRequest = new URLRequest (youTubeLink);
loader.contentLoaderInfo.addEventListener(Event.INIT, handlerLoaderInit);
loader.load(req);
logMessage ("Loading YouTube URL..");
}
Good example here, works great on its own, however when you do use this inside of any other part of the app these type errors occur,
**
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at /private::startLoading()
at /__submitButton_click()
at [mouseEvent]
Runtime error is at
loader.contentLoaderInfo.addEventListener(Event.INIT, handlerLoaderInit);
**
This is using flex 3,
Cheers
Drop me a link if you get this one figured out.....
I'm trying to include and play youTube video from with a swf I have prepared but I don't know how to do it. I've read the code but I'm not an expert and I don't really understand it. Sorry.
I have this information: the target movieChild within the swf is "videoBox" and I want to repace it with the video from youTube so the video is exactly the right size and position.Can this be done? the URL of the video is: "http://www.youtube.com/watch?v=hs94ojVu7t"
However I need to load a video inside an AS2 project i made, but the youtube player appears inside my as2 project, where in flex ONLY the video appears.
How would I do this in AS2 ?
@Allen: I really didn't get what problem you are facing? Can you please write it again, may be in technical words or with some code you are trying to use?
Thanks
-abdul
Ok let me re-phrase. When I put together the example using AS3 in Flex, it worked perfect, and only the actual video shows.
But when I tried the AS2 example inside my AS2 project, the YouTube video player appears, just like on the youtube website, with the red srubber bar and the whole youtube video player interface. Thats the problem.
I hope i explained better this time, and maybe you can point in me the right direction on how to "remove" the youtube player interface from my AS3 project.
Thanks Abdul!
Has anyone managed to recreate the play/stop button within flash?
I have been on vacation hence I couldn't respond to your comments. I would do it very soon, one by one, I would try to answer all queries.
Thanks
-abdul
i'm sure somes of you will be please to find the equivalent of da ActionScript method in PHP5 ;-)
I give you my sourcecode tested with success :-)
don't forget sharing and diversity and everything get your favorites videos with joy ;-)
greetings from france
/*
* @ edited by Nicoweb 2007
* 12/08/2007 19:13pm
* youtube-url-source-00.php
*/
ini_set("max_execution_time","3600");
$baseUrl = "http://www.youtube.com/v/%s";
$idVideo = "3IcwG0jUFxU";
$urlVideo = sprintf($baseUrl,$idVideo);
$baseVideoUrl = "http://www.youtube.com/get_video.php?%s";
ob_start();
// get via CuRL da great library so fine ;-)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urlVideo);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
$out = ob_get_clean();
$strs = explode("&t;=",$out);
$final = explode("\n",$strs[1]);
$t = $final[0];
$finalUrlVideo = getVideoUrl($idVideo,$t);
$filv = file_get_contents($finalUrlVideo);
$fo = fopen("file.flv","w+");
$fw = fwrite($fo,$filv);
$fc = fclose($fo);
/* getVideoUrl ( string idVideo , string tValue ) */
function getVideoUrl ($id,$tval) {
global $baseVideoUrl;
return sprintf($baseVideoUrl,"video_id=".$id."&t;=".trim($tval));
}
@Nicoweb: That looks neat, thanks for it..
-abdul
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
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
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?
Can I have the source for your YouTubeClientSideDemoFlex.swf file?
@Hendra:- The first code snippet in above post is the source-code of YouTubeClientSideDemoFlex.swf...
-abdul
Which, sorta brings us back to square one. How are the players deriving the subdomain that the .flv is coming from?
-abdul
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];
where "ffMSy8usAlc" is the youtube id
Works with FLVPlayback component in Flash 8.
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.
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 ;-)
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....
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;
}
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-
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.
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.
when the given link;
it is redirected to the link as mentioned below;
http://www.youtube.com/swf/l.swf?video_id=3IcwG...
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
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/Zo52T...
Regards
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?
> 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
Check this out:-
1) Go to http://www.abdulqabiz.com/temp/flvPlayer.swf
2) Paste this url: http://youtube.com/get_video?video_id=gttvfPjLV...
It works fine..
-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);
};
Abdul,
But your example code in Flex AS3 seems to go to YouTube directly! How does this work?
try to handle your php/asp flv source in flash like:
your-folder/whatever/stream.php/anything-here.flv
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
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
Did you try appending &.flv in the end of URL, see if it works?
-abdul
thanks
Sorry, you have to wait and post the comment again..
-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=e... 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?
Thanks for feedback.
-abdul
Thanks,
Mike
the link to the .flv is all i need.
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
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
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;
}
}
}
http://www.abdulqabiz.com/files/YouTube_Client_...
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=3IcwG...
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=3...
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
enjoy guys
http://www.youtubeflashplayer.com
I just started to learn flex, and I am working on developing YouTubeWidget. and It looks like this converting feature would be great help to me.
However, it doesn't work to me. The link generated from here doesn't work with VideoDisplay. Also, your sample also doesn't work.
Is this out of date formula for converting URL to Flv URL?
Thank you!
Seems to no longer work.
Would be nice to have an update, ... but ...
Greg
Seems to no longer work.
Would be nice to have an update, ... but ...
Greg
doesn't work now! t urlVars = undefined
<ol>
<li>Get the URL to the clip you wish to load. This URL must be of the form http://www.youtube.com/watch?v=dMH0bHeiRNg. If you are getting the URLs from the standardfeeds url (http://gdata.youtube.com/feeds/api/standardfeeds/), the URL to the clip is the media:player item
</li><li>Load this URL and scan the source of the page for the "watch_fullscreen" URL. It will look something like this:</li></ol>
 Â
var fullscreenUrl = '/watch_fullscreen?fs=1...
<li>Take everything after "watch_fullscreen?" and save it to a variable (we'll use params)
</li><li>Generate your FLV url as follows:
</li>
  finalURL = "http://www.youtube.com/get_video.php?" + params;
And there you go. Hope this works for you.
Even though I can get the t var and perform a GET on the get_video url, i get a 404 not found on the download.
But if I use a web browser and view the source, and manually extract the t variable, the download link works.
Maybe it's something to do with cookies...
Your blog helped me to develop Youtube widget player. Thank you!
As other people said, the url format had been changed. Does anyone find the new way of getting flv url?
Sorry for not responding to your comments, seems it's time for an updated post for latest workaround.
I have been busy with many things, one of those is Chromeless AS3 Player (YouTube) Wrapper - It uses ExternalInterace or LocalConnection (both options would be there).
Once it's ready, I would post it.
Thanks
-abdul
http://pogopixels.com/blog/getting-the-url-of-a...
This script is wrong! Anyone know working code?
Does somebody know how to build the the donwload url for the new youtube video pages format?
I always promise to update it but can't, due to various other commitments. I am sure, there are a lot of folks who are taking care of it, i.e. always coming up with new ways to do things.