The simplest way to make a playlist is to generate a text file with the web address for each media file, and to save this file with a .m3u extension. The M3U universal playlist does allow for some more options, but simply listing the locations to the files is enough. To generate my playlists I use the Bash script below, which runs nightly on my server through a cron job, so my playlist stays up to date without me having to think about it. The script lists all the media files in the "LOCAL_SOURCE" directory, replacing the local path with the HTTP path, as well as replacing a few special characters with their URL encoding (for instance, spaces are replaced with %20). I use this script for Apache, other servers may have different requirements. In the days I did everything in Windows, to make my playlists I would go into a DOS prompt and do something like "dir /S /B *.mp3 >> playlist.m3u" within the directory holding all my music, then run a macro in a text editor to make any necessary modifications to produce the playlist.
| generate_playlist.sh |
#!/bin/sh
LOCAL_SOURCE="/home/nick/files/Media/Audio/Music/"
HTTP_SOURCE="http://randombytes.net/music/"
PLAYLIST="playlist.m3u"
FILE_TYPES="mp3 wma m4a wav ogg flac"
if [ -e $PLAYLIST ]
then
echo "Playlist already exists. Replace with new playlist?"
rm -i $PLAYLIST
fi
if [ ! -e $PLAYLIST ]
then
for i in $FILE_TYPES; do
echo "Adding" $i "files to playlist."
find $LOCAL_SOURCE | grep -e '\.'$i'' | sed -e 's#'$LOCAL_SOURCE'#'$HTTP_SOURCE'#g' | sed -e 's/ /%20/g' | sed -e 's/#/%23/g' | sort >> $PLAYLIST
done
fi
|
It is important to make sure when generating a playlist that the media files over HTTP are actually where you think they are. Special characters in the filename may translate to some strange character code when accessed over HTTP. What these characters are translated to will depend on the HTTP server being used. The best way to check what characters are being translated to something else, and what this something else is, is to enable directory listing on the server and observe how the server lists the files. A rather fail-proof method of making a playlist could be to use the directory listing page generated by the server. But once everything is working, I like to keep directory listing disabled as a security measure. This way, even if someone over the internet knows of the location of all your media files, they won't know what's there, and therefore can't download it (unless, of course, they had your playlist).
To avoid problems with special characters, I try not to use special characters in my filenames. When I notice a song in my playlist doesn't load, I'll check why my playlist generator failed, and either add a "find and replace" to my script, or rename the file to get rid of the offending characters.
I should also add, if your ISP blocks port 80, it is not necessary to stream over 80. Any open port will do!
Now for the client side... Most media players can stream at least a few file formats through HTTP, however, just because a player can play a file format locally doesn't mean it will be able to play a stream. Here is a short list of players I've used, and what I've been able to stream with them: