Apache::MP3::Playlist - Manage directories of MP3 files with sorting and persistent playlists


 # httpd.conf or srm.conf
 AddType audio/mpeg    mp3 MP3

 # httpd.conf or access.conf
 <Location /songs>
   SetHandler perl-script
   PerlHandler Apache::MP3::Playlist
   PerlSetVar  SortField     Title
   PerlSetVar  Fields        Title,Artist,Album,Duration


Apache::MP3::Playlist subclasses Apache::MP3::Sorted to allow the user to build playlists across directories. Playlists are stored in cookies and are persistent for the life of the browser. See Apache::MP3 and Apache::MP3::Sorted for details on installing and using.


The "playlist" class in the apache_mp3.css cascading stylesheet defines the color of the playlist area and associated buttons.


Apache::MP3::Playlist overrides the following methods:

 run(), directory_bottom(), control_buttons() and directory_top().

It adds several new methods:

$result = $mp3->process_playlist

Process buttons that affect the playlist.

$hashref = $mp3->lookup_descriptions(@uris)

Look up the description fields for the MP3 files indicated by the list of URIs (not paths) and return a hashref.

@list = $mp3->playlist([@list])

Get or set the current stored playlist. In a list context returns the list of URIs of stored MP3 files. In a scalar context returns an array reference. Pass a list of URIs to set the playlist.

Linking to this module

The following new linking conventions apply:

Add MP3 files to the user's playlist

Append "/playlist.m3u?Add+to+Playlist;file=file1;file=file2..." to the name of the directory that contains the files:

 Two favorites</a>
Add all MP3 files in a directory to the user's playlist:

Append "/playlist.m3u?Add+All+to+Playlist" to the name of the directory that contains the files:

 Madonna'a a Momma</a>
Delete some MP3 files from the user's playlist:

Append "/playlist.m3u?Clear+Selected=1;playlist=1;file=file1;file=file2..." to the name of the current directory.

NOTE: the file names must be absolute URLs, not relative URLs. This is because the playlist spans directories. By the same token, the current directory does not have to contain the removed song(s). Example:

 No longer a virgin, alas</a>
Clear user's playlist:

Append "/playlist.m3u?Clear+All=1;playlist=1" to the name of the current directory.


 <a href="/Songs/Springsteen/playlist.m3u?Clear+All=1;playlist=1">
   A virgin playlist</a>
Stream the playlist

Append "/playlist.m3u?Play+All=1;playlist=1" to the name of the current directory.


 <a href="/Songs/Madonna/playlist.m3u?Play+All=1;playlist=1">
    Stream me!</a>
Stream the playlist in random order

As above, but use "Shuffle+All" rather than "Play+All".

Stream part of the playlist

Append "/playlist.m3u?Play+Selected=1;playlist=1;file=file1;file=file2..." to the name of the current directory.

NOTE: the files must be full URLs. It is not strictly necessary for them to be on the current playlist, so this allows you to stream playlists of arbitrary sets of MP3 files.


 Madonna and John, together again for the first time</a>


This module uses client-side cookies to mantain the playlist. This limits the number of songs that can be placed in the playlist to about 50 songs.


Chris Nandor came up with the idea for the persistent playlist and implemented it using server-side DBM files. I reimplemented it using client-side cookies, which simplifies maintenance and security, but limits playlists in size.


Copyright 2000, Lincoln Stein <>.

This module is distributed under the same terms as Perl itself. Feel free to use, modify and redistribute it as long as you retain the correct attribution.


Apache::MP3::Sorted, Apache::MP3, MP3::Info, Apache

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 266:

You forgot a '=back' before '=head1'

Around line 270:

'=item' outside of any '=over'