I recently had to make a player for theremnantmusic.com. In it they wanted the song title to show up and change with each new song.
What was so hard about this was that the radio station was using an custom program made for them for their CCM radio station kduvfm.com. So I had to figure out how the heck I could get that program to convert the xml list and it just wasn’t happening. Couldn’t get a hold of the dude who wrote the program because he has been shunned by the company he worked for at the time of making.
Being in a time crunch anyways I had my good friend from Godbit forums Philip Schalm who slammed it out for me. Basically it takes the xml file from where the radio stations server spits it out to on the ftp and then formats it for the web so I could manipulate it. Just put your variables in place of mine and you should be able to do whatever you want with it.
Here is an example of the xml file coming into the site.
<?xml version="1.0" encoding="ISO-8859-1"?> <nexgen_audio_export> <audio ID="id_1"> <type>Song</type> <title>Title:Reinventing Your Exit</title> <artist>By:Underoath</artist> </audio> </nexgen_audio_export>
Here’s what the PHP4 script he came up with:
$xml = file_get_contents('PATHTOYOURXMLFILE.xml') or die("Can't open remote files!");
$arr = array();
$cur_tag = "";
function start_el_handler($parser,$name,$attribs) {
global $cur_tag;
$cur_tag = $name;
}
function end_el_handler($parser,$name){}
function char_handler($parser,$data) {
global $cur_tag, $arr;
$arr[$cur_tag] .= $data;
}
$parser = xml_parser_create();
xml_set_element_handler($parser, "start_el_handler", 'end_el_handler');
xml_set_character_data_handler($parser, "char_handler");
xml_parse($parser,$xml);
echo '<ul id="ID-FOR-STYLING">';
echo '<li> Artist: ' . preg_replace('/^By:?/','',$arr['ARTIST']) . '</li>';
echo '<li> Title: ' . preg_replace('/^Title:?/','',$arr['TITLE']) . '</li>';
echo '</ul>';
Phil’s note: The PHP4 method has some large disadvantages, namely that it can only parse a single <audio> at a time. It’s not too difficult to hack on the ability to have multiple artists, but it’s more difficult to do it well and in a way that makes the script easy to modify for other uses. Ultimately, though, you should use the awesome new PHP5 XML extensions (you are using PHP5, right?) as they make this kind of thing a lot easier. What follows in a PHP5 example using the SimpleXML extension (and automatically allows multiple songs):
$xml = file_get_contents('PATHTOYOURXMLFILE.xml') or die("Can't open remote files!");
$xml = new SimpleXMLElement($xml);
echo '<ul id="ID-FOR-STYLING">';
foreach ($xml->audio as $song) {
echo '<li> Artist: ' . preg_replace('/^By:?/','',$song->artist) . '</li>';
echo '<li> Title: ' . preg_replace('/^Title:?/','',$song->title) . '</li>';
}
echo '</ul>';
Hope this helps, Click Here to view player.
No related posts.