Sat Jan 12 12:38:58 EST 2008

Home Music Server


This is sort of old news but I thought I'd share a little project I've done at home.

The CD player on the living room stereo finally died, well mostly. It plays sometimes, other times it doesn't. So, rather than replacing it I decided it would be time to be able to play the tunes from my computer downstairs on the stereo upstairs. I was previously using gnump3d to stream music at work, but due to a sever security flaw I decided it was time to drop it and try something new. After asking around it was suggested I take a look at Slimserver. It's commercially developed, GPL'd, and has a slew of features. It runs fairly well but seems not as stable as gnump3d. I've had to restart the daemon a couple times a week. It is designed to work with hardware that they sell (price range from $300 to about $1000) but will work with most any player. I've tried winamp, xmms, and amarok.

Setting up the server software isn't that hard as there are packages for most popular distributions at the download site. It also run on Windows and Mac which is cool. If you run Slackware there is a slackbuild available at slackbuilds.org. Once that's installed you just connect whatever player you choose to run to the stream at http://<serverip>:9000/stream.mp3.

As far as getting the music up to the stereo I went as frugal as I could. Rather than buying a Slimdevice of some sort I just used a spare small form factor PC I had around that has integrated wireless. It's small enough to fit behind a speaker of the stereo. It's running Slackware 12.0 (any distro will do) and connected automatically on boot to the stream with mplayer. I'm not sure how to do such thing with Windows but the way I did it was to write a small script and call it in my rc.local. The goal was to have it connect on boot and automatically retry connecting if it lost connection to the stream. I put the script below somewhere in my path and called it start_mplayer. I'm sure it could be improved by someone who actually know scripting well but it seems to work. Of course, the username, password, and IP address aren't real.
killall mplayer
mplayer -user USERNAME -passwd PASSWORD http://123.45.67.89:9000/stream.mp3
if [ $? = 0 ]; then
        start_mplayer
fi
The idea is that it kills all instances of mplayer just to make sure no extra mplayer processes are running taking up resources. It runs mplayer and connects to the stream. If mplayer exits with an error it restarts itself.

Finally, in my rc.local I put:
/usr/bin/start_mplayer 2> /dev/null 1> /dev/null &
There is a 1/8" audio to RCA cable I had laying around that I think I bought at RadioShack ages ago that connects the PC's sound card to the CD in line of the stereo. Now I just choose what I want to play from my laptop and it come out of the stereo.

This works pretty well for the most part. Like I said, I have to restart the slimserver daemon a couple of times a week. The client computer also looses it's wireless connection about once a day. The client issue is probably because the wireless chipset it has is not supported well under Linux.

Posted by Brian | Permalink | Categories: Computers and Technology | |