0

I was making a player which calls videos from youtube.com and displays it in my flash playback component. The script loads the videos fine but when i want the flash to load the same video ID from an external XML data source, it loads the youtube player API but not the video. Here is the code

Security.allowDomain("www.youtube.com");
Security.allowDomain("*");
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(582.2,373.1);
    my_player.cueVideoById("53OyPYa7SEI",0);
    my_player.playVideo();

}

This script loads the video from youtube.com with an specific ID which i have defined at

my_player.cueVideoById("53OyPYa7SEI",0)

later i defined and XML file called "videos.xml" where i passed the youtube link and tried to call the video from that xml file in flash. But the problem comes there. Here is the xml code

<?xml version="1.0" encoding="ISO-8859-1" ?>
<videos>
<VIDEO url="http://www.youtube.com/watch?v=53OyPYa7SEI" id=1/>
<VIDEO url="http://www.youtube.com/watch?v=53OyPYa7SEI" id=2/>
</videos>

Can anyone help me out to call the video from an XML file?

phihag
  • 278,196
  • 72
  • 453
  • 469
Amit
  • 1
  • 4

1 Answers1

0
var XMLPath:String = "videos.xml";
var xmlSlideshow :XML;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, onXMLLoadComplete);
//xmlLoader.addEventListener(ProgressEvent.PROGRESS, xmlLoadingAction);
//xmlLoader.addEventListener(ErrorEvent.ERROR,ErrorAction);
xmlLoader.load(new URLRequest(XMLPath));

function onXMLLoadComplete(e:Event):void {
    xmlSlideshow = new XML(e.target.data);
    trace(xmlSlideshow.VIDEO.@url);
}

after that

my_loader.load(new URLRequest(xmlSlideshow.VIDEO.@url));

Here is a good online tut. Just go through it.

Benny
  • 2,250
  • 4
  • 26
  • 39
  • @ Benny thanks for replying so fast. I really appreciate this. I did the necessary changes with my xml file as u suggested. But the player still loads the video with the defined ID which is defined at 'my_player.cueVideoById("53OyPYa7SEI",0);' my_player is the target name for where i need to load the target videoID. How to pass the target ID in that target ?? – Amit Sep 03 '11 at 10:29
  • "defined ID which is defined at" what? Have u complete the sentence? – Benny Sep 03 '11 at 10:31
  • Previously if it was playing. It should play now. – Benny Sep 03 '11 at 10:33
  • @ Benny thanks for replying so fast. I really appreciate this. I did the necessary changes with my xml file as u suggested. But the player still loads the video with the defined ID which is defined at 'my_player.cueVideoById("53OyPYa7SEI",0);' my_player is the target name for where i need to load the target videoID. How to pass the target ID in that target ?? – Amit Sep 03 '11 at 10:35
  • store in xml and then locate it, like video path. – Benny Sep 03 '11 at 10:37
  • I have changed ur xml in ur question. chk with that. – Benny Sep 03 '11 at 10:41
  • Is video should not play without the id? – Benny Sep 03 '11 at 10:43
  • Nope. Stack overflow will not appreciate that. They will fire us. Hope ,t here will be simple mistake, just relax and think. Good Luck – Benny Sep 03 '11 at 10:47