Saturday, September 25, 2010

Load A YouTube Video Inside A SWF File

Flash Video Flash Video

The YouTube API

the YouTube AS3 API doesn't require you to download and install a special component for you to be able to play YouTube videos inside your project, instead you directly load a special YouTube file during runtime using the Loader Class and then use that file to play any video you want.

The basic process outline for loading the API and using it is as following:

  1. Configure Domain Security to allow YouTube to communicate with the swf.
  2. Create a variable to hold a reference to the YouTube player (http://www.youtube.com/apiplayer?version=3).
  3. Use the Loader Class to load the YouTube API file
  4. Create event handlers to control the player once the API file has successfully loaded and got initiated.
  5. Play the YouTube video by the API ID (_OBlgSz8sSM",0).

Security.allowDomain("www.youtube.com");

var my_player:Object;

var my_loader:Loader = new Loader();
my_loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
my_loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);

function onLoaderInit(e:Event):void{
addChild(my_loader);
my_player = my_loader.content;
my_player.addEventListener("onReady", onPlayerReady);
}

function onPlayerReady(e:Event):void{
my_player.setSize(640,360);
my_player.cueVideoById("5KWHPg7g5WI",0);
}

play_btn.addEventListener(MouseEvent.CLICK, playVid);
function playVid(e:MouseEvent):void {
my_player.playVideo();
}
pause_btn.addEventListener(MouseEvent.CLICK, pauseVid);
function pauseVid(e:MouseEvent):void {
my_player.pauseVideo();
}

Finding the ID

The ID of the video is the string at the end of a YouTube URL that follows the v=.

5KWHPg7g5WI

youtube url

Player API Youtube API Overview Guide. The YouTube APIs and Tools let you bring the YouTube experience to your webpage, application, or device. The Data API lets you perform most of the operations a normal YouTube user can on the YouTube website. The Player APIs let you control the YouTube player using JavaScript or ActionScript. There is the basic embedded player you are used to seeing as well as the chromeless player that lets you create your own player controls.

Lastly there are the Widgets, and a custom player that you can embed on your webpage, even if you are not a web programmer.


YouTube video player with live preview playlist

youtube player

This player is for YouTube videos, it uses YouTube API batch processing to get video's information, which allows to fetch data for up 50 videos with a single API call.

Only $17 at Activeden

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...