March 1, 2010

Drupal + XSPF

Having worked on many Drupal sites with music players I have used a number of solutions but never quite found something that worked perfectly for me. Recently I have done a number of sites that required the ability to have a play list that is easily managed by the client without messing around with xml files and ftp uploads. There are a couple solutions for this but i am going to focus on one solution which is using the XSPF Playlist module.

Step 1: Enable the modules.

- XSPF Player - http://prdownloads.sourceforge.net/musicplayer/xspf_player-0.2.3.zip?dow...

- XSPF Playlist Module - http://drupal.org/project/xspf_playlist

- Views 2 - http://drupal.org/project/views

- CCK - http://drupal.org/project/cck

- Upload - Comes in Drupal core.

Step 2: Create your content type.

next you'll want to create a custom content type to upload the mp3 files to(admin/content/types/add) , I named mine playlist items.

You can get rid of the body since you won't need it unless you want to use the node in another page then pop down to "Workflow Settings" and turn on file attachments. All you are going to need is a title and the Standard file attachment.

Also note that the file size is going to be constrained by what your server settings will let you upload so if you want to add large size mp3's that will need to be tweaked. Your ability to do this will depend on your hosting situation.

Step 3: Configure XSPF Playlist.

After you have created your content type you will need to enable it in XSPF to allow the module to create playlists from the nodes (admin/settings/xspf_playlist).

Here you can title the playlist that will be created as well. In content settings you select your CCK and click save. Now there's a little bit of a trick i found, if you are using the admin menu module you will need to flush your cache on it for the playlist settings to show in the menu. You can then go to this link through admin menu or /admin/settings/xspf_playlist/name-of_your_content_type. Here you will select the field that contains the mp3 and thumbnail to show in the player for this setup you will want "Drupal: Upload Attached Files". (Please note that currently there seems to be a problem in the D6 version with correctly pulling the thumbnail. You can, however, set a default cover to show for all tracks.

Step 4: Create your view.

Once you have your content type and your XSPF settings done you will need to create a view to generate the xml for the player to read. Start by creating a new node view, the main display you will need is the FEED display.

here's a list of the basic settings to get it going.

- items to display:Unlimited

- Style:XSPF Playlist

- Row Style: Node XSPF

You'll need to give it a path i just used /playlist for mine and then as always you'll need some filters so select node type and as a rule i always add node published: Yes

you can then sort the view however you choose and save your work.

Note: This view does not utilize any fields so other than the couple style settings, path, sorts and filters there is not much to set up.

Step 5: Embed the player in a block/page.

The last thing to do is set up the actual player. To do that you will need to place the downloaded swf somewhere in your drupal install's file structure. I like to place all my swf's in my themes directory to keep things clean. Once you have done that you will need to either create a page or a block, set the input format to full HTML and enter the following embed code in in the body:

<object type="application/x-shockwave-flash" width="400" height="170"

data="location-of-the-player-swf?playlist_url=feed-url">

<param name="movie"

value="location-of-the-player-swf?playlist_url=feed-url" />

</object>

Set the location for the swf to the path from the root of your install and enter the path to the feed you set up for the playlist_url and that's it. You have an audio player that requires no xml knowledge to maintain.

This will get you started with a basic set up from there you can use views sorting, filters and arguments to control your playlists however you want. Depending on your ability there are many players out there to skin and use on your site that accept XSPF playlists.