I am trying to call a video from youtube.com in flash as2. The video link is stored in a external xml file. Flash works fine when i try to call a video with an exact flv location but it crashes whenever i try to call a youtube url. I am stuck with the codes. I was wondering if the video can start at a specific GMT that needs to be stored in xml. Please help.
Here is the flash code:
Security.allowDomain("www.youtube.com");
Security.allowDomain("*");
//initializing xml loading
// load the xml file
xmlData = ne开发者_运维问答w XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("videos.xml");
// parse the nodes of the xml into an array
function loadXML() {
vidArray = new Array();
aNode = this.firstChild.childNodes;
len = aNode.length;
for (var n = 0; n != len; n++) {
vidArray[n] = aNode[n].attributes.url;
}
}
output_vid.onEnterFrame = function() {
trace(vidArray[0]);
output_vid.contentPath = vidArray[0];
};
and here is the xml code (video.xml)
<?xml version="1.0" encoding="ISO-8859-1" ?>
<videos>
<video url="http://www.youtube.com/watch?v=jYa1eI1hpDE"/>
</videos>
Please help !!
Load the XML into flash... Get your url in a string, say "string3" for example..
string3 = "http://www.youtube.com/watch?v=jYa1eI1hpDE"
now replace "watch?v=" with "v/"
var stringArray:Array=string3.split("watch?v=");
string3 = stringArray.join("v/");
now string3 = "http://www.youtube.com/v/jYa1eI1hpDE"
That is the exact flv location on all youtube videos.... no need to do anything else.
精彩评论