tags:

views:

269

answers:

3

So I have a website that queries a database with information about music, with id3 information and file location information. I would like to use THIS to add a little playable mp3 player beside each of the search results, but I can't figure out how to do this without generating the xspf file, which would mean I would need an xspf file for every file in the database, which I don't want to do.

A: 

An XSPF file is fairly small. It's just an XML document with song locations and titles. Just generate it dynamically.

<?
header('Content-type: application/xspf+xml');
$tracks = array(
    'Song 1' => '/media/song1.ogg',
    'Second Song' => '/media/second_song.ogg',
    '3rd Song' => '/media/3rd_song.mp3'
);
$xml = new XmlWriter();
$xml->startDocument('1.0','UTF-8'); 
$xml->startElement('playlist');
$xml->writeAttribute('version','1');
$xml->writeAttribute('xmlns','http://xspf.org/ns/0/');
$xml->startElement('trackList'); 
foreach ($tracks as $title => $location) {
   $xml->startElement('track');
   $xml->startElement('title', $title);
   $xml->startElement('location', $location);
   $xml->endElement(); // track
}
$xml->endElement(); // trackList
$xml->endElement(); // playlist
$xml->endDocument();
$xml->flush();
?>
Calvin
+1  A: 

Never mind, found out you don't need a playlist for one song if you don't want to.

Specto
Maybe you could post the link here, then.
troelskn
A: 

Here are a few:

troelskn