New YouTube API and related changes.

In case you haven’t heard, YouTube has released a new API to make it easier for Flash and JS developers to use YouTube content.

Without even touching the API I have already seen some benefits. The old youtube player used to get stageWidth and stageHeight and attempt to scale itself. This worked fine for people who were simply enbeding the player into their HTML pages but obviously posed a problem for people trying to put the player on their Flash pages.

I just fired up an old file I was working on and the new YouTube player swf works exactly as you’d expect it to, namely, the player constrains itself to the dimensions of it’s parent clip.

Some of the other changes allow you to import a chromeless video (even the controls are stripped) and then control the video through your own code.

For people who where already taking flv’s from YouTube’s website, non of this will change anything. But for people who where unsure about whether or not it was kosher to pull the flv’s, and by extension refrained from doing so, these changes will be much welcomed. It provides all the benefits of directly pulling the FLV while simultaneously being blessed/endorsed by YouTube.

They’ve also given the ability to upload videos from your own site.

New information about the youtube AS3 API can be found here: http://www.scotflash.co.uk/blog/?p=442

This entry was posted in Flash news and tagged , , . Bookmark the permalink.

11 Responses to New YouTube API and related changes.

  1. desperate says:

    hi paul, would you like to help me?

    i try to load youtube videos in a flash movieclip but it doesn’t work.
    goes like:
    ytPlayer = new MovieClipLoader();
    ytPlayer.loadClip(“http://gdata.youtube.com/apiplayer?key=my_key&enablejsapi=1″, “film320″);

    the chromeless player is loading so far, but i fail loading a video into it.

    on (release) {
    ytPlayer.loadVideoById(“PJ-A9mUvgAE”, 0);
    }

    do you have an idea?

  2. admin says:

    Have you tried to use the example that can be found on youtube?
    http://code.google.com/apis/youtube/flash_api_reference.html

  3. desperate says:

    yes, I’ve tried in several ways, i.e. exactly how they described in the example…

    i also added the javascript parameter (“allowScriptAccess”, “always”) into my html page that loads the swf;

    so if you like to have my code, i could send it to you…

  4. admin says:

    It should work from within flash or in an html page so
    So (”allowScriptAccess”, “always”) should not make any difference.
    Below is the code i have pulled out a working fla.

    var vidArr:Array = new Array("z8H_LgChJXk", "RR-vaMVPebc", "BWt54n7rkKA", "REOCJOVj3sM");

    ytPlayerLoaderListener = {};
    ytPlayerLoaderListener.onLoadInit = function() {
    var loadInterval:Number = setInterval(checkPlayerLoaded, 250);
    };
    function checkPlayerLoaded():Void {
    if (ytplayer.isPlayerLoaded()) {
    ytplayer.addEventListener("onStateChange",onPlayerStateChange);
    ytplayer.addEventListener("onError",onPlayerError);
    loadIndicator._visible = false;
    }
    }
    function onPlayerStateChange(newState:Number) {
    trace("New player state: "+newState);
    }
    function onPlayerError(errorCode:Number) {
    trace("An error occurred: "+errorCode);
    }
    ytPlayerLoader = new MovieClipLoader();
    ytPlayerLoader.addListener(ytPlayerLoaderListener);
    ytPlayerLoader.loadClip("http://www.youtube.com/v/"+vidArr[0],ytplayer);

  5. desperate says:

    thanx paul, i did that, must be another problem…

    i will tell you…

  6. Good site I \”Stumbledupon\” it today and gave it a stumble for you.. looking forward to seeing what else you have..later

  7. badgroovy says:

    How do you destroy the last clip seen, when you load a new one ?

  8. badgroovy says:

    Duh, i just saw the “destroy() function ” ….

  9. zoran says:

    I have a question…
    I uploaded swf video on web server, and it works perfectly, but there is a catch. There is no video control!
    I dont know what to do. when i publish on my web browser it works like a charm, but when it is uploaded there is no video controls…
    can someone help me ?
    please…

  10. Have you used the code from previous posts?
    It works for me
    http://www.scotflash.co.uk/youtube/

  11. Once i get some free time i will make a working source available.
    Just not had the time this year :/