subscribe: Posts | Comments

Play youtube videos in flash tutorial

21 comments

Like i promised many of you , here is a quick video tutorial on how to load youtube videos in flash , the only thing is im running out of time and i have many other projects to deal with so its a kinda fast so Listen and watch carefully , if you have a question regarding the tutorial you can always post a comment .

Things to remember :

  • AbdulQabiz youtube php engine that is downloadable with the example sourcecode ( Many thanks to him ) .
  • Dont forget to get your own developer ID since all the rest requests requiers the dev id e.g:
    http://www.youtube.com/api2_rest?method=youtube.users.get_profile&dev_id=YOUR_DEV_ID
    NOTE THAT YOU WONT NEED A DEV_ID IF YOU WILL MANUALLY ADD THE YOUTUBE VID LINKS .
  • Read the INTRODUCTION and the DOCUMENTATION .

Things to consider :
The application i built at http://www.zainals.com/xperments/youtube is reading the XML file from youtube , now i didnt explain much about that because its a different topic but if you would like , i can make another video about xml when im free , but for the time being google it , you can find many tutorials at kirupa gotoandlearn.com and tutorialvid.com

Unfortunatly youtube disabled or changed their crossdomain xml file as mentioned on abdulqabiz blog , and will have to use some sort of a proxy script e.g :

<?php
$dataURL = "http://www.youtube.com/api2_rest?method=youtube.videos.list_featured&dev_id=YOURDIV_ID";
//note that this will not follow redirects
readfile($dataURL);
?>

Enjoy the following vid … Enlarge the vid for a clearer preview …

  1. mank1327 says:

    Nice, man. I downloaded the CS3 trial, so I’ll get a dev ID and try this out today.

    By the way, the missing email from the photo upload arrived yesterday. It must have come by boat or something.

    Later!

  2. Hey Mank :) good to know that you downloaded that , remember to set your publish settings to Actionscript 2.0 when following my tut because im still working on that version .

    lol @ the boat , probablly DNS or Queue issue …

    if you need help you know where to find me !

  3. lol after watching my vid (which i made quickly at work) its really not that clear but it should give you some idea about it …. ( i sounded sleeepy )

    i also recommend that you watch the XML videos by Lee >> :
    XML basics :
    http://www.tutorialvid.com/viewvideo/558/Flash_Tutorial_XML_Basics/?ref=actionscripter

    XML video play list :
    http://www.tutorialvid.com/viewvideo/559/XML_Video_Playlist___Flash_Tutorial/?ref=actionscripter

  4. Hi my name’s Cory I couldn’t get my flash file for this tutorial right it says something like
    *** Security Sandbox Violation ***
    Connection to “http://www.youtube.com/get_video.php?video_id=” . $v . “&t=”. $t . “&flv halted – not permitted from

    Is it ok if you can send me the flash file along with the php file for this tutorial? I’ll be grateful !
    my email is:********************
    Thank you very much
    Cory

  5. Hi Cory , i have removed your email so you dont get spammed …
    when security sandbox appears it means that another domain is trying to access the current player domains , you can avoid this by adding the following code at the top of your actions layer :

    System.security.allowDomain("*");

    Security sandbox

    read more about it on adobe technote or livedocs .
    but from what i see the recieved variables are not shown , its like the PHP code is not proccessed and returns basic TEXT string …

    here are the files :
    files

  6. Im really stuggling with this, have been trying for hours now. I can construct the url ok using the php script, and remake the url in flash ok as well, if i paste this url in a browser i can even download the .flv file.

    However if i use the path as the .contentPath it will not load the movie, i just get this error in the trace window

    1005: Invalid xml: URL: “http://www.youtube.com/get_video.php?video_id=s1fz8pYly9k&t=OEgsToPDskJlt-hGmLAioouhnfwj6FxF&.flv&FLVPlaybackVersion=1.0.1″ No root node found; if url is for an flv it must have .flv extension and take no parameters

    if you can help i will be very grateful!

  7. hi mate …
    like the error said , there is something wrong with your variable out put , which is in your case “http://www.youtube.com/get_video.php?video_id=s1fz8pYly9k&t=OEgsToPDskJlt
    -hGmLAioouhnfwj6FxF&.flv&FLVPlaybackVersion=1.0.1″

    now to get the flv playing in your application the extension at the end should be only .flv

    here is a sample that you can download , have a look properly and fix your code a bit to get the proper output http://www.zainals.com/loads/blog/xperments/youtube.rar

    let me know how this goes i’ll be glad to sort it out for ya .

  8. tnx man u explain well good job

  9. Hi

    I have developed a similar kind of application to view you tube videos. It works perfectly as a standalone desktop application but when i put it on the server and try to run it on the web i am not gettin any outputs.. can anyone help me out with this.

  10. *
    Actually the problem is when i run the application from a server I am not able to retrieve the xml from the specified path (i.e http://gdata.youtube.com/feeds/videos?…. )

    can anyone please help me out with this!

  11. @Arun:

    > Actually the problem is when i run the application
    > from a server I am not able to retrieve the xml from
    > the specified path (i.e

    That’s because Google/YouTube doesn’t have liberal crossdomain.xml, their policy file only allows Google’s properties.

    You can use a server-side proxy to route your requests..

    -abdul

  12. Hey What happened with the video
    I came to watch your video again but it is not published anymore, how can I do to watch it again?
    sorry for my bad english…

  13. Heres another example
    http://jaxxrr.110mb.com/other/fs3.html
    and heres the sourcecode
    http://jaxxrr.110mb.com/other/flash-fullscreen-youtube.zip

    the fullscreen part is nothing special really.. one line of script on a button

    on (release) {
    Stage.displayState = “fullScreen”;
    }
    but you also need to edit the html file and set the allowFullScreen parameter from false to true, it is there just set it to true (don’t write it twice like I did :) )

    so either

    or
    AC_FL_RunContent( … “allowFullScreen”, “true”, … )

    depending on how you launch the flash..

    Also make sure your html file does’nt get overwritten when publishing again.. go to publish settings and uncheck html

    this info is also in flash CS3 help :)

    cheers

  14. I’m trying to load 3 different youtube videos in a movie depending on 3 buttons.

    My code is:

    pest_1.onRelease = function() {
    _root.createEmptyMovieClip(“mc”,0); unloadMovie(mc);
    loadMovie(“http://www.youtube.com/v/HO-BcoXYGuA&autoplay=1&noscale=true”,mc);
    mc._x=15;
    mc._y=40;
    mc._xscale=90;
    mc._yscale=80;
    }

    pest_2.onRelease = function() {
    unloadMovie(mc);
    loadMovie(“http://youtube.com/v/zUjMMKuzBPQ&autoplay=1&noscale=true”,mc);
    }

    pest_3.onRelease = function() {
    unloadMovie(mc);
    loadMovie(“http://youtube.com/v/ZjHMSE7-oME&autoplay=1&noscale=true”,mc);
    }
    stop();

    I really don’t know why, i can see the first two videos. When i try to load the third, the movieclip show grey and any video can be played anymore.

    The tutorial you made isn’t aviable anymore. Can you give me some advice?

  15. i fixed the vid mate , i dont know what is exactly going on with your script , i need sometime to see it , busy at the moment …
    :)

  16. If you get into some errors, like 1005;

    try to handle your php/asp flv-rendering-source in Flash like:
    your-path-way/to/heaven/ STREAM-HANDLER . php / anything-here.flv
    .php COULD be .asp here, :-p

    Flash adds ?xxxx to the file, so faking an extension in any other way won’t work.

  17. sallaboy says:

    Hi,

    does your example suitable for actionscript 2.0 ?
    If it is, how did you solved the cross domain problem ?
    Ho do I make AbdulQabiz youtube php engine work in actionscript 2.0 ?

    Sallaboy

  18. darkneo says:

    I read a lot of articles to play a youtube video in flash/ flex and now I’m lost!! I don’t understand! Is there an easy way to play a youtube video in Flash/Flex without have a sandbox error now? I follow an example on abdulblog but now, without the “free crossdomain.xml” , we can’t play a youtube video without have an sandbox error. So how we can? You talk about a server side proxy but I don’t understand how it can be use to play the video. To retrieve XML, I understand, but to play the video into the flash I don’t understand. Please help if you have a way to resolve!

  19. Error opening URL ‘http://www.youtube.com/v/PAlNMaxZVTk

    how do I solve this issue

  20. Hi,

    Wow this is fantastic…exactly what I need, but I am having some issues. I can the php file to echo the url..

    Flash is giving me the error:

    1005: Invalid xml: URL: “http://www.youtube.com/get_video.php?video_id=s-bJSPRRCf8&t=OEgsToPDskJHVGuTHdCpGalSEkuTmk3P&.flv&FLVPlaybackVersion=1.0.2″ No root node found; if url is for an flv it must have .flv extension and take no parameters

    Ah, any idea you be SO GRATEFULLY!

    Cheers Breon

  21. Breon,
    I believe youtube changed somthing, I used to have this working, but it hasn’t worked for a while….

Leave a Reply