...

View Full Version : XSPF generator



mattsnow
05-22-2008, 08:25 PM
I am trying to use this player (http://musicplayer.sourceforge.net/) to play music on my site and it works fine, as you can see here (http://mattsnow.co.uk/test/). this is great for just a few songs, but i have about 300 here that have been uploaded and it would be an extremely boring task to add each song to the xspf playlist file. Does anyone know about a playlist generator or something that can take the .mp3 files name and put it in the playlist file?

_Aerospace_Eng_
05-22-2008, 08:28 PM
If you know the format of the xml file that is needed then you can use php to generate the xml file for you.

<?php
/*
This is a sample file that reads through a directory, filters the mp3/jpg/flv
files and builds a playlist from it. After looking through this file, you'll
probably 'get the idea' and'll be able to setup your own directory.
*/


// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts
$filter = ".mp3";
// path to the directory you want to scan
$directory = "somedirectory";


// read through the directory and filter files to an array
@$d = dir($directory);
if ($d) {
while($entry=$d->read()) {
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false)) {
$items[] = $entry;
}
}
$d->close();
rsort($items);
}

// third, the playlist is built in an xspf format
// we'll first add an xml header and the opening tags ..
header("content-type:text/xml;charset=utf-8");

echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
echo " <title>Sample PHP Generated Playlist</title>\n";
echo " <info>http://www.*******************/</info>\n";
echo " <trackList>\n";

// .. then we loop through the mysql array ..
for($i=0; $i<sizeof($items); $i++) {
echo " <track>\n";
echo " <title>".$filename."</title>\n";
echo " <location>$items[$i]</location>\n";
echo " </track>\n";
}

// .. and last we add the closing tags
echo " </trackList>\n";
echo "</playlist>\n";


/*
That's it! You can feed this playlist to the SWF by setting this as it's 'file'
parameter in your HTML page.
*/

?>
The above code IS the xml file so link to that as the playlist. Just change the directory to match where your mp3 files are stored at.

mattsnow
05-24-2008, 05:22 PM
This looks like what I'm looking for, although I'm a bit confused on what exactly you do. Could you post more detailed instructions?

_Aerospace_Eng_
05-24-2008, 06:51 PM
You change the directory of where the mp3s are stored at. You also need to know how a playlist looks for the player. As I said you NEED to know the structure of the playlist. Do you know this? If so then post an example.

siggma
12-22-2008, 08:14 AM
I'm very new to PHP. My first project is an almost valid (http://validator.xspf.org/) xspf playlist generator that scans a directory and generates an xml (xspf) playlist from the id3 tags it finds in mp3 files. This project uses the get_id3() class (http://getid3.sourceforge.net/) available at sourceforge.net.

An html title is provided for search engines as well as a default "noimage.jpg" used for all mp3s without a matching jpg image. JPG Images that match the mp3 file name are included in the playlist making it easy to set a default image for an entire directory and customize images for individual tracks.

You can get it here: xspf.php playlist generator home page (http://www.trbailey.net/xspf/)

Any comments are welcome.
-Tom



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum