Dynamic mp3 playlist in Drupal 6

I tried generating dynamic playlists with swftools or jw player module without success, but finally got Views to generate a playlist feed imported into an embedded mp3 player on the fly. These are the modules needed:

  • CCK + filefield (for the mp3 files)
  • Views bonus pack (to export fields to XML).

And the embeded mp3 player that I used can be found in http://www.premiumbeat.com/flash_music_players/.

The view filters by content of type song (in my case) and displays fields node title and the song content with a URL to file format. Adding a “path” as custom label for this last field helps to construct the correct xml tag for the mp3 player later. The view is displayed in a feed with a style of xml file and a path of playlist.xml for this example. At this point the supplied views-bonus-export-xml.tpl.php template file needs to be overriden to make it match with the xml file expected by the premiumbeat mp3 player (see the xml file that comes as an example with the player download). Instead of the <node> tags I used <item>, and I also needed to get rid of the <xml> tags and added <playlist>. The resulting file:

print '<?xml version="1.0" encoding="UTF-8" ?>';
<?php foreach ($themed_rows as $count => $row): ?>
<?php foreach ($row as $field => $content):
$label = $header[$field] ? $header[$field] : $field;
<<?php print $label; ?>><?php print $content; ?></<?php print $label; ?>>
<?php endforeach; ?>
<?php endforeach; ?>

The generated xml file looks like this:

<?xml version="1.0" encoding="UTF-8" ?><playlist>

The last thing needed is to embed in a block the player. The only thing we have to be careful with is the path, both to the xml playlist generated by the view and the actual mp3 player swf file.

--><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<div id="player-holder">
<script type="text/javascript">
var options = {};
options.playlistXmlPath = "http://example.com/playlist.xml";

var params = {};
params.allowFullscreen = "true";
params.allowScriptAccess = "always";

swfobject.embedSWF("http:/example.com/sites/all/themes/mytheme/originalmultiple/OriginalMusicPlayerPlaylist.swf", "player-holder", "250", "180", "9.0.0",false, options, params, {});
</script><!-- END PLAYER EMBED CODE -->

That´s all!


Posted on December 19, 2010, in Uncategorized. Bookmark the permalink. 3 Comments.

  1. dhakhsina moorthy

    hai buddy!great work. can u explain this audio playlist creation in more details?

  2. Great post as this is exactly what I was looking to do, I was able to add the player and format the xml correctly so that they player picks it up but getting ‘xml playlist not found’ I think that is what you were referring to in the changing of the tags part about but not understanding how you changed the tag to be “”

  3. Forget I asked. Missed the part about overriding the view. I did that and now it works. Great stuff, thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: