Wednesday 27 March 2013

How to import you-tube video on flash using as3

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("XYDCH-vudJk",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();
}*/




7 comments:

  1. I have used this code and it worked well at the beginning when i first tested my project. However, after sometime, i tested the project again i found that the youtube movie appears with the play button on the movie but when clicked, the movie disappears and the youtube logo is shown on the bottom left side!!!
    when I click the play button I created as you mentioned in the code above, the loading circle appears but nothing happens and only the logo is there!!
    what should i do??? :(

    ReplyDelete
    Replies
    1. Do you got any error like (SecurityError: Error #3207: Application-sandbox content cannot access this feature.) ?

      Delete
  2. Hi. I'm trying to add this code on a movieclip for an android app. But it just hang when I try to test run on my pc and my phone. What should I do?

    ReplyDelete
    Replies
    1. you should install adobe air app to display (flash content) video on android device

      Delete
  3. Nice piece of code. When I tried it displayed ......

    #3207: Application-sandbox content

    Anyway around this.

    ReplyDelete
  4. Nice piece of code. When I tried it displayed ......

    #3207: Application-sandbox content

    Anyway around this.

    ReplyDelete
    Replies
    1. Try going to the publishing settings (File > Publish Settings), and at the bottom, change "Local Playback Security" feature to have the value of "Access Network Only"

      Delete