Streaming Your Music Collection

If you’re like me, you’ve taken the time to rip your entire music collection to mp3. I have a huge collection of CDs and like to listen to them in the car with my portable mp3 player. I also like to listen to them at work. Since I have a PC and net access, I just stream them and pick the stream up with xmms (or mpg123 or winamp). I use the liveice plugin for Xmms and the Xmms::shell perl module to remotely control the Xmms session and manage playing tunes. There are many ways to do this, but this method works for me

Things you need

  • A broadband internet connection.
  • Knowledge of firewalls and NAT. My previous
    article on mod_proxy via apache will also be useful since your typical home setup has just one public IP address.
  • To do the above apache mod_proxy trick, you need to understand DNS and have a domain that you control.
  • A collection of tunes. Mine is shared on my internal network via NFS and Samba.
  • An understanding of streaming technology. The software links below should tell you what you need to know.

What to do

You’ll be downloading a pile of software. Everything for me was available as Debian packages so apt-get (packagename) worked for me. I’ll link to the original sites here.

First and foremost, you need xmms. You also need icecast. Along with that you’ll need liveice and the liveice-xmms plugin. What this will do is send the output of whatever is playing in xmms to your icecast server.

The other thing you’ll need is lame because liveice needs to reencode mp3’s on the fly. I encode mine for high quality and they’re much too large to stream. Thus I re-encode them on the fly to a paltry 64kbps stream. This is bandwidth friendly and my workstation running xmms can more than handle the load.

In Xmms just go to the Options dialog and select the Effects/General plugins tab. From there you can choose to configure and enable the liveice plugin. There are boxes for the stream bitrate (640000 in my case) and the encoder choice (lame)./p>

You’re almost set. You need to set up your firewall and/or apache proxy to get the traffic in to your icecast server. Icecast runs by default on port 8000. So for the first option, pass that port through and then you’d connect your remote mp3 software to http://www.yoursite.com:8000 to catch the stream.

Because I’m stuck behind a highly restrictive firewall/http proxy at work, I needed to use the apache proxy magic and DNS. First I set up a new DNS alias pointing to my single IP address — ie. music.yoursite.com. Then I set my apache mod_proxy on my firewall to pass the traffic through to my internal icecast server (ie. 10.10.1.5 below).

NameVirtualHost your.external.ip.address

<VirtualHost your.external.ip.address>
   ServerAdmin webmaster@yoursite.com
   ServerName music.yoursite.com
   ProxyPass / http://10.10.1.5:8000/
   ProxyPassReverse / http://10.10.1.5:8000/
   ErrorLog /var/log/apache/music.yoursite.net/error_log
   TransferLog /var/log/apache/music.yoursite.net/access_log
<VirtualHost>

So at work I use mpg123 ( I could use any mp3 player really) to connect to my stream remotely: mpg123 -p http://my.work.proxy http://tunes.yoursite.com. If Xmms+liveice-plugin+icecast is running on the server, I get a stream. If not I get a standard HTTP 404 error.

There’s one more issue — remotely controlling that Xmms session. There’s lots of ways to do that and the control plugins to xmms are available at the xmms site. I’ve experimented with some of the web-based plugins and xmms-shell as well. I settled on the perl module Xmms::shell. I can ssh to my site and then use perl -MXmms -e shell to start xmms and manipulate the playlist to my heart’s content. I used apt-get libperl-xmms on my Debian setup but non-Debian users might do this:

perl -MCPAN -e shell
CPAN> install Bundle::Xmms

If you’re not familiar with CPAN you should read up on it first. Once I’m in the Xmms shell I can do almost anything I can do in the GUI.

As always, you need to be concerned about security when you start opening holes on your firewall and running new servers. In this case, you’ve got a firewall, apache, mod_proxy, icecast, and liveice-xmms to be concerned about. That means you’ve got to watch for vulernabilities in all of these items. This is hardly a mission-critical service so it’s no big deal to turn it off should a new vulnerability be discovered. You may also want to restrict it further via your firewall and your apache proxy server using Limit directives in your VirtualHost container.


Scott Harney

   (GPG key)
<>

Resume


An online copy of my resume (PDF)

Photo Album


My current pictures via Flickr.
Older family pictures.

    Wedding


    I got married on 9/4/2004. So click for details, already.

    Old stuff


    Links and writings from older versions of this site
    Old stuff
    Oldest stuff

    Free DNS