rss xml feed for flash player

Having problems installing or using kPlaylist.

rss xml feed for flash player

Postby aghori » Fri Jun 27, 2008 12:56 am

If you want to have xml file created to feed to flash player as a playlist.xml to play songs from last streams, I have put the code together. It seems to work but sometimes it doesn't unpredictably. I would like Aba to look at this code and see if its correct.

I have put a demo at http://www.gaijatra.com/music/gpod_demo
of flash player where you can listen to kp last streams on a flash player. (it might not work, last time I checked , was working)

here is the code

class gpodrss
{
function gpodrss($title)
{
global $setctl, $phpenv;
$this->lf = "\r\n";
$this->data = '<?xml version="1.0" encoding="';
if (UTF8MODE) $this->data .= 'UTF-8'; else $this->data .= 'UTF-8';
$this->data .= '"?>'.$this->lf;

$this->data .= '<playlist version="1" xmlns="http://xspf.org/ns/0/">'.$this->lf;
$this->data .= '<trackList>'.$this->lf;
}



function add_gpod_track($f2, $sid, $link)
{
global $GMUSIC_AD_IMG_URL;
$f2 = new file2($sid, true);
if ($f2->ifexists())
{
$fd = new filedesc($f2->fname);
if ($fd->found && $fd->m3u)
{
$url = httpstreamheader3($fd->fid, $sid, $f2);
$url = str_replace(array('&c','&file'), array('&amp;c', '&amp;file'), $url);
$artist = $f2->id3['artist'];
$album = $f2->id3['album'];
$title = $f2->gentitle(array('title'));
if (!empty($url))
{
$this->data .= '<track>'.$this->lf;
$this->data .= '<location>'.$url.'</location>'.$this->lf;
$this->data .= '<creator>'.$artist.'</creator>'.$this->lf;

$this->data .= '<album>'.$album.'</album>'.$this->lf;
$this->data .= '<title>'.$title.'</title>'.$this->lf;
$this->data .= '<annotation>'.$f2->gentitle(array('artist', 'title')).'</annotation>'.$this->lf;
$this->data .= '<duration>'.vernum($f2->id3['lengths']).'</duration>'.$this->lf;

$kpi = new kpimage(false, $f2->drive, $f2->relativepath);
if ($kpi->find())
{
$kpi->resize();
$imgurl = $kpi->geturl(true);
} else $imgurl = $GMUSIC_AD_IMG_URL;

$this->data .= '<image>'.$imgurl.'</image>'.$this->lf;
$this->data .= '<info>http://'. $_SERVER['HTTP_HOST'] . '/music/gmusic/</info>'.$this->lf;
$this->data .= '</track>'.$this->lf;
}
}
}
}


function ship()
{
$this->data .= '</trackList>'.$this->lf;
$this->data .= '</playlist>'.$this->lf;
header('Content-Disposition: inline; filename=gpodrss'.lzero(getrand(1,999),6).'.xml');
header('Content-Type: application/xml');
header('Content-Length: '.strlen($this->data));
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
echo $this->data;
}
}


////////////////////////

function create_gpodrss($clink=false)
{
global $cfg, $setctl, $phpenv;
$res = $this->getlast($cfg['rsslaststreamcount']);

$rss = new gpodrss(get_lang(286));

while ($row = mysql_fetch_assoc($res))
{
$f2 = new file2($row['id'], true);
$fd = new filedesc($f2->fname);
if ($fd->found && $fd->m3u)
{
if ($clink) $link = $setctl->get('streamurl').$phpenv['streamlocation'].$f2->weblink(0,0,'sid', false); else $link = $setctl->get('streamurl').$phpenv['streamlocation'];
// $rss->additem($f2->gentitle(array('title', 'artist')), $f2->gentitle(array('title', 'artist', 'album')), $link, $row['utime'], '');
$rss->add_gpod_track($f2, $row['id'], $link);
}
}
$rss->ship();
}

/////////////////////

if (isset($_GET['gpodrss']))
{
$ca = new caction();
$ca->updatelist();
$ca->create_gpodrss(true);
die();
}
//////////////////////

it creates the xml file as


<?xml version="1.0" encoding="UTF-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<trackList>
<track>
<location>http://gaijatra.com/music/gmusic/index.php?streamsid=5&c=-1&file=.mp3</location>
<creator>1974 AD</creator>
<album></album>
<title>Parelima</title>
<annotation>1974 AD - Parelima</annotation>
<duration>231</duration>

<image>http://localhost/music/gmusic/images/gmusic_ad1.gif</image>
<info>http://gaijatra.com/music/gmusic/</info>
</track>
<track>
<location>http://gaijatra.com/music/gmusic/index.php?streamsid=10&c=-1&file=.mp3</location>
<creator>1974 AD</creator>
<album>Best of 1974 AD</album>
<title>Tyo Raatko</title>
<annotation>1974 AD - Tyo Raatko</annotation>

<duration>232</duration>
<image>http://localhost/music/gmusic/images/gmusic_ad1.gif</image>
<info>http://gaijatra.com/music/gmusic/</info>
</track>
...
</trackList>
</playlist>
/////////////////////

but as you can see the c value ? c=-1 which is supposed be something like c = 1-105590(some number)
sometimes it creates the right location link sometimes it doesn't.


In anycase with working code you could have the last streams play on a flash player on other pages of your site.

If you are reading this Aba, pls reply. There are some other issues I would like to ask you.
thanks a lot
aghori
 
Posts: 30
Joined: Thu Jun 05, 2008 10:36 pm

Re: rss xml feed for flash player

Postby aba » Fri Jun 27, 2008 1:28 am

aghori wrote:but as you can see the c value ? c=-1 which is supposed be something like c = 1-105590(some number)


If you get -1 one here (The format is <userid>-<sessionid>), which means that kP did not detect the cookie which again means that the request was unauthenticated. (Log on first and then do the request.). If it should be a service you can use without being logged on, you have to design it in another fashion. For instance, look the way the RSS is handled.
aba
Site Admin
 
Posts: 2325
Joined: Wed May 08, 2002 9:19 am

Postby aghori » Fri Jun 27, 2008 1:48 am

Well, i just put the code together form kprss and jwplayer. anyway, I posted the code how would you make it work? this would serve a great purpose that i could have flash player on other pages from where visitors could listen to the last streams.

If you could suggest me how to make it work I would appreciate a lot. It does work sometimes. Thanks
aghori
 
Posts: 30
Joined: Thu Jun 05, 2008 10:36 pm

Re: rss xml feed for flash player

Postby aghori » Wed Jul 16, 2008 10:17 pm

I thought this would be very useful if there is rss feed to the flash player because that way visitors to a site can atleast listen t few songs that were last streamed without having to log on to kplaylist or even the new visitors could kind of preview the songs from kplaylist.

The code i posted just creates the xml file that can be fed to flash player but it doesn't play the songs unless you are logged, that defeats the whole purpose. I am sure this can be made work easily, please reply if you have any idea on this.

Thanks
aghori
 
Posts: 30
Joined: Thu Jun 05, 2008 10:36 pm


Return to Community support



cron