Streaming Music Over HTTP
Streaming music over HTTP is very easy, and supported by most media players. However, what media player you decide to use will determine which file types you will be able to stream. But luckily the software on the server side is the same regardless of the client. On the server, all you need is an HTTP server (like Apache), and a playlist for the clients, linking to all the media files available.

The simplest way to make a playlist is to list the locations of all the media files over HTTP, and save this as a 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 Linux 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. 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 the playlist.

#!/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

Below is a somewhat useless script for making WPL playlists. I made this when I thought Windows Media Player did not accept the M3U playlist generated above, but it seems I made a mistake when I thought this. It may be that earlier versions of Windows Media Player don't accept M3U, but either way, I already wasted my time making this, so I thought I'd throw it up here.

#!/bin/sh
LOCAL_SOURCE="/home/nick/files/Media/Audio/Music/"
HTTP_SOURCE="http://randombytes.net/music/"
PLAYLIST="playlist.wpl"
FILE_TYPES="mp3 wma wav"
TITLE="Web Playlist"

if [ -e $PLAYLIST ]
then
  echo "Playlist already exists.  Replace with new playlist?"
  rm -i $PLAYLIST
fi

if [ ! -e $PLAYLIST ]
then

  echo '<?wpl version="1.0"?>
<smil>
        <head>
                <meta name="Generator" content="Microsoft Windows Media Player -- 10.0.0.4036"/>
                <title>'$TITLE'</title>
        </head>
        <body>
                <seq>' > $PLAYLIST

  for i in $FILE_TYPES; do
    echo "Adding" $i "files to playlist."
    find $LOCAL_SOURCE | grep -e '\.'$i'' | sed -e 's#'$LOCAL_SOURCE'#                  <media src=\"'$HTTP_SOURCE'#g' | sed -e 's#\.'$i'#\.'$i'\"/>#g' | sed -e 's/&/&amp;/g' | sed -e "s/'/\&apos;/g" | sort >> $PLAYLIST
  done

  echo '                </seq>
        </body>
</smil>' >> $PLAYLIST

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:

I'd be interested in hearing about other people's experience streaming in different media players. I've yet to find a single player in Linux, Mac, or Windows that can stream most files, runs fast, and displays the playlist nicely. I usually stick to XMMS in Linux, iTunes with Mac, and iTunes or Windows Media Player in Windows.
Back to Home
Contact Me