Sunday, March 11, 2007


Flash Player for Youtube : I have wrote a simple application that can see video contents of Youtube only by remote control such as Rimo. I would like to optimize the application for Wii, but I don't buy Wii in my home yet X-<

I wrote the client only using Flash 8, and the main source code of ActionScript is the following. You can get the all source codes that includes the flash file and the server side file from the link.
var rssXML = new XML();
rssXML.ignoreWhite = true;

var rssItemNum = 0;
var rssItemTitle = new Array();
var rssItemURL = new Array();
var currtemNum = 0;

function updateItem(xml) {
var channelNode = xml.firstChild.firstChild;
var channelNodesNum = channelNode.childNodes.length;
if (channelNodesNum <= 0)
return;
rssItemNum = 0;
rssItemTitle = new Array();
rssItemURL = new Array();
for(var i = 0; i < channelNodesNum; i ++) {
if(channelNode.childNodes[i].nodeName.toLowerCase() == "item") {
var itemNodesNum = channelNode.childNodes[i].childNodes.length;
var itemName = "";
var itemUrl = "";
for(var j = 0; j < itemNodesNum; j ++) {
if(channelNode.childNodes[i].childNodes[j].nodeName.toLowerCase() == "title") {
itemName = schannelNode.childNodes[i].childNodes[j].firstChild.nodeValue;
}
if(channelNode.childNodes[i].childNodes[j].nodeName.toLowerCase() == "link") {
itemUrl = channelNode.childNodes[i].childNodes[j].firstChild.nodeValue;
}
}
rssItemNum++;
rssItemTitle.push(itemName);
rssItemURL.push(itemUrl);
}
}
}
rssXML.onLoad = function(result) {
if (!result)
return;
updateItem(this);
if (0 < rssItemNum) {
flvMedia.stop();
flvMedia.contentPath = rssItemURL[0];
flvMedia.play(0);
}
}
rssXML.load("http://www.cybergarage.org/flash/youtube.xml");

function updataContentIndex(offset)
{
currtemNum += offset;
if (currtemNum < 0)
currtemNum = rssItemNum-1;
if ((rssItemNum-1) < currtemNum)
currtemNum = 0;
}

var flvPlayListener:Object = new Object();
flvPlayListener.complete = function(){
updataContentIndex(1);
flvMedia.stop();
flvMedia.contentPath = rssItemURL[currtemNum];
flvMedia.play(0);
}
flvMedia.addEventListener("complete",flvPlayListener);

var keyListener = new Object();
keyListener.onKeyDown = function() {
if (Key.getCode() == Key.RIGHT) {
updataContentIndex(1);
flvMedia.stop();
flvMedia.contentPath = rssItemURL[currtemNum];
flvMedia.play(0);
}
if (Key.getCode() == Key.LEFT) {
updataContentIndex(-1);
flvMedia.stop();
flvMedia.contentPath = rssItemURL[currtemNum];
flvMedia.play(0);
}
}

Key.addListener(keyListener);
I wrote a php file for the client to output a RSS format of YouTube :: Recently Featured that includes URLs of the FLV files directly. To run this sample of PHP, you might have to add the following patch into HTTP.php because the head function might ignore query strings of the specified URL.
# diff HTTP.120.php HTTP.php
153a154,155
> if (0 < @strlen($purl['query']))
> $path = $purl['path'] . "?" . $purl['query'];
Please check it :-)

This page is powered by Blogger. Isn't yours?