Vol. 13: Music Control System

Set up a cheap wireless server for your song collection.

By Andy Seubert

Illustrations by PARS/E Design



+ Downloads & Extras:

Intranet Music System

Here, the author Andy Seubert shares the details of setting up your music system on both Windows and Linux.

WINDOWS

Recycle Your Old Computer into a Jukebox

Like many before me, I had spent hours and hours ripping all of my CD collection to my computer. If I could just plug my computer into my receiver, then I could hear the music all over the house. Unfortunately, that would also mean listening to YouTube video sounds all over the house. Since I couldn't stand that, I figured out a way to dedicate an old computer as my music server and make it do dual duty as a web server, so that I could access it via a wi-fi connection from my laptop. This way, I can see my music library as if it's on a web page, and click the song I want to hear. Now when I have a party, my friends and I can build a playlist of songs to set the mood, and I can even save those playlists for later. Additionally, I was not finding any system for doing this within my price range: under $50. Using mostly on-hand stuff and free software downloaded from the internet, the price point was easily achieved. The only things I had to buy were a nice long audio cable and an adapter to connect it to my Intranet Music Control System.

1. DESIGNATE SERVER PC

I happened to have a very old Packard Bell PC, which I retired from being my home desktop. To play music and serve a web page, you don't need much computing power. Hopefully you already have a PC, which you can use. You can use your everyday desktop for this and it won't really add any load. The only drawback to using the same computer you surf on is that the sound of those YouTube videos will go out the same sound card that will be connected to your home stereo system, which could be an odd experience. If you have only one computer, you could install a second sound card that would play the music over your house speakers, and then have one reserved for your local speakers. For this, we will assume one Windows XP computer with all updates applied from Microsoft update to be dedicated as the server. We will also assume you have a desktop PC with your music living on it, and that you have a home network already in place. Having a wireless home network really adds a great dimension to this project.

2. CONNECT AUDIO

I wanted my server-player to live in the basement, well away from my stereo receiver, which is in my living room, so I went to RadioShack and got myself a long audio cable. They have a 20-footer for $15. It has RCA connectors on both ends, but my PC needs a stereo headphone jack to connect speakers to it. I happened to have one on hand, but you can get one at RadioShack while you are picking up your cable.

On the back of your server-player, you will see your sound card connections. Generally the green one is the speaker out connection; it usually has an icon with an arrow pointing away from (out) the plughole, with radiating sound lines across the arrow. Your server may also have a headphone jack. Generally, the headphone jack is amplified internally and the lineout connection is not. If you have trouble with the sound quality from one, try the other. I have had good luck with both.

Just plug the other end of the cable into your stereo receiver. It's a good idea to label the front of the receiver to indicate which selector to choose in order to listen to the music from your server-player. I attached mine to the Tape-2 input RCA jacks on my receiver, and then put a piece of tape next to the Tape-2 button on the front. This way my kids can listen to Abba anytime they want without wondering which button to select.

3. SET STATIC IP ADDRESSES

Since you will need to put an address into your browser to get to the controls of you new music player-server, you don't want that address to change. This means you will need to set a static IP address on your server. Also, in order for the server to always be able to connect to your shared music, you will need to set a static IP address on your desktop with the music files as well. Since neither computer will ever leave your network, this will not cause any problems. Choose IP addresses that you can remember. For this project, use 192.168.0.10 for the server-player and 192.168.0.15 for your music sharing desktop PC. I sometimes find that it is helpful to make little labels on your computers with their IP addresses noted for future reference.

The properties of your "Local Area Connection," which you find in the network section of the control panel, contains the IP settings. Click Start, choose control panel, double-click on Network Connections, and that opens up the window containing a list of network connections. Right-click on the connection that is plugged into your home network and choose Properties. Select the Internet Protocol (TCP/IP) and then click the Properties button. This brings up the dialog where you choose to have a static IP address; set it and also choose to set the DNS servers manually.

Click the radio button marked "Use the following IP address:" and fill in the following information with details to match your network:
IP address: 192.168.0.10
Subnet mask: 255.255.255.0
Default gateway: 192.168.0.1

Then choose the radio button marked "Use the following DNS server addresses:" and fill in:
Preferred DNS Server: 192.168.0.1
Alternate DNS Server: 208.678.202.202

A brief overview of DNS might be in order. DNS stands for "Domain Name System". While computers require IP addresses to determine the locations of other computers, humans require names. For example, in our home network you will be able to remember that 192.168.0.10 is your music server. You would not want to remember the numbers for google.com, yahoo.com, makezine.com or cnn.com. We humans can much better remember names, and DNS allows for mapping or translating names to the numbers that our computer overlords require. To get your DNS action, just set your DNS server address to your gateway's IP address. That is the address of the computer through which all your internet connections go. Usually your DSL modem or your cable router is able to service DNS naming requests; in most home networks, that is 192.168.0.1. I like to use "opendns", which is a very nice, free DNS service that works anywhere.

Click OK and then OK again to save your changes and reset your IP address. Make sure you can still reach a web page to test that you set everything correctly and that your network connection is still active.

4. CONNECT TO YOUR MUSIC LIBRARY

You already have your music ripped and presumably use Songbird or it's equivalent to play it. Let's leave the music where it is. We can just share it out to the network, and the server player can pick it up from wherever it's already living.

The easiest way is to find the folder that contains it all and share that. Let's imagine yours is in your "My Music" folder. If your username is Bob, then your "My Music" folder lives at this address on your hard drive:
"C:\Documents and Settings\Bob\My Music"

Open up Windows Explorer by right-clicking on "My Computer" and choosing "Explore" (keyboard shortcut: If your keyboard has a Windows key, hold that down and press the letter "e" to open Windows Explorer). Navigate to the above-mentioned folder and right-click on it. Choose Properties and then click on the Sharing tab. Check the box called "Share this folder on the network" and put a Share name in the field there with no spaces. I prefer to call mine "music".

If you have not already enabled sharing on your computer, you will get prompted to read more about sharing and security. For now, just click where it says that you know about the risks, and want to go ahead and share this folder. Next, you will need to tell the player-server where the music is. Assuming you set your music-sharing PC with an IP address of 192.168.0.15, open a command prompt on the player-server and issue this command:
>net use M: \\192.168.0.15\music

You should get:
The command completed successfully

That command will map the letter M:\ as a drive on the server-player system (M for Music, right?). Then you can set that as your music library on your server's music-playing software, and it will actually be pulling the music from your desktop music repository. Being able to do this kind of thing is what makes computer networks really useful.

5. TURN OFF WINDOWS SYSTEM NOISES

Since you are going to connect your house's speakers to your windows computer, you will probably not want to hear every bonk and click that happens when Windows wants you to know something, and I have grown tired of that little tune it plays when it boots up. So open up the Windows control panel and click on the "sounds and audio devices" icon. Choose the "sounds" tab and change the sound scheme from whatever it is set on to "no sounds".

6. INSTALL AND CONFIGURE PLAYER AND WEB CONTROL CENTER SOFTWARE

Winamp is a very nice, free, full-featured media player. It has a large user community and one generous member of that community has created a plugin for us to use called "AjaxAMP".

Here is what you need to do:
Download and install Winamp and AjaxAMP.
During install, Winamp wants to install some "extras". These we do not need, so unselect the Winamp toolbar, free extras, and free music.
After installing Winamp, run it. It will prompt you to add music the first time you run it. Click "Don't show this again" and click the Cancel button. Close Winamp.
Install AjaxAMP and then open Winamp again, then click options > AjaxAMP preferences:

  • Change the server port to 80
  • Click Library and then Add Directory to choose the M:\ drive that we connected earlier.

In order to have Winamp start every time the computer boots, some trickery is required. Since Winamp won't behave when run as a service, you must enable auto logon for your user and also put a shortcut to Winamp in your startup folder. Enable automatic logons by following these instructions from this page: http://windowsxp.mvps.org/Autologon.htm Click Start, Run, and type CONTROL USERPASSWORDS2, then click OK. Select the user account from the list (the account to which you want to automatically logon). Uncheck "Users must enter a user name and password to use this computer" option, and click OK. Type the user account password and complete the process.

For Windows XP Home, don't try to auto-login as the built-in administrator because you'll receive an error message. Put a shortcut to Winamp into your startup folder like this: Open Windows Explorer, and navigate to the Winamp program folder, which by default is in C:\Program Files\Winamp. Right-click on winamp.exe and choose create shortcut. Right-click on the new shortcut and choose cut. Navigate to your startup folder, which is located at C:\Documents and settings\Bob\Start Menu\Programs\Startup (where Bob is your username) and right-click in that folder and choose paste.

This procedure will make the system automatically login using your username and password, and launch Winamp without requiring any interaction from you.

Autologon can be a security vulnerability because if someone sits in front of your player-server, they will be logged in as you without having to know your password. To mitigate this issue, run your player-server "headless," which means unplug the keyboard, mouse, and monitor. Most computers from the last few years or so are able to handle this configuration. You may hear a series of beeps upon boot, which is the BIOS saying that there is no keyboard connected. An additional level of security that you should add is to turn on the screen saver. Choose one like the blank, which is not too processor-heavy, and check the box which says on resume, password protect, and you will have locked your console from curious visitors.

7. ENABLE REMOTE ADMINISTRATION

You will want to connect to your server-player from time to time. Things like Windows updates, troubleshooting, and general hacking will be desirable. You have 2 choices: Remote Desktop or VNC. Unfortunately Microsoft decided that in Windows XP if you are logged in via remote desktop, you cannot be trusted to reboot your PC, and so removed the option from the start menu. Thanks, Bill.

Because of that you should use VNC. UltraVNC is a powerful, easy-to-use, and free software that can display the screen of another computer (via internet or network) on your own screen. The program allows you to use your mouse and keyboard to control the other PC remotely. It means that you can work on a remote computer as if you were sitting in front of it, right from your current location. That is just what we want. Download the installer from here: http://www.uvnc.com/download/index.html http://prdownloads.sourceforge.net/ultravnc/UltraVNC-102-Setup.exe?download Download the same installer to both your server-player and your desktop PCs.

Server-player install notes:
When you get to the select additional tasks part, choose

  • Register UltraVNC server as a service
  • Start or restart UltraVNC service
  • Configure Admin properties
The Default properties window will come up at the end. The only thing you need to do there is set a password in the VNC password box.

The same package contains both the server and the viewer. You need the server on your server (duh), and the viewer is what you use to see the desktop on the server. During the installation on your desktop PC, just accept all of the defaults. Once installed, open the client on your desktop PC. It is in Start > All Programs > UltraVNC > UltraVNC Viewer. Put your server-player's IP address in the Server Address field and click connect. You will be prompted for the password, and once you enter that, you will be shown your server's desktop. To click Ctrl+Alt+Del, you will need to click on the little CAD icon in the upper left end of the menu bar.

8. CONFIRM FUNCTION

Go to your wi-fi-enabled laptop on your home network and open a web browser. Enter the server-player's IP address into the address bar like this: http://192.168.0.10 If all went as planned, you should see the AjaxAMP web page with the controls and the playlist on the left hand side of the screen, and your library on the right side. Choose a song and click play to get music to flow from your stereo receiver's speakers.

LINUX

INSTALL FEDORA

Things to keep in mind during the Fedora installation:

  • You can choose to include support for "Web Server," and you should click that checkbox. Also click "Customize Now"; the goal is to install as few packages as possible since you are installing on a computer with very limited CPU power.
  • Remove all "Desktop Environments" (Gnome is checked by default, so UNcheck that).
  • UNcheck "Graphical Internet."
  • Do CHECK the box for "Windows File Server" in the "Servers" section.
  • UNcheck X Window System.

MOUNT MUSIC

Make a place for the music to mount into:
]# mkdir /usr/local/music

Then test your ability to mount your shared folder:
]# mount -t cifs //192.168.0.125/music /usr/local/music
Mount is the command used to attach devices to directories. In this case, the "device" is our shared music, which lives on our Windows desktop computer. The command -t cifs tells mount what kind of file system the "device" is formatted as; //192.168.0.125/music is the device, and /usr/local/music is the location on our file system, where we want to make the remote files available to us.

To make the share mount at boot time, enter a line into the file like this:
]# vi /etc/fstab
//192.168.0.125/music /usr/local/music cifs username=xxx,password=xxx 0 0

INSTALL MDP

MDP is the Music Player Daemon. MDP has a very nice wiki. There are clear instructions for various Linux distros on the MDP wiki: http://mpd.wikia.com/wiki/Install#Fedora_Install_Procedure

Install a good repository like Livna so you don't get caught in dependency hell.

]# rpm -ivh http://rpm.livna.org/livna-release-7.rpm
Preparing... ########################################### [100%]

   1:livna-release     ########################################### [100%]

]# yum install mpd will find dependencies and ask you if it's OK to proceed [Y/N] Type Y and hit enter. After yum downloads the packages, it will ask you about importing GPG keys. Since we trust Livna to package safe Red Hat packages, this will allow us to check the signatures of future packages for authenticity, so answer yes to import those 2 keys. They are the Fedora Red Hat public GPG keys.
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID a109b1ec
Importing GPG key 0xA109B1EC "Livna.org rpms " from /etc/pki/rpm-gpg/RPM-GPG-KEY-livna

DISABLE SELINUX

To allow PHP to connect to the MPD server, you need to disable Selinux controls.

http://ryandaigle.com/articles/2005/9/27/mythweb-howto-fix-fsockopen-function-fsockopen-unable-to-connect-to-127-0-0-1-6543-permission-denied-error

]# vi /etc/selinux/config
SELINUX=disabled

CONFIGURE MPD

The MPD package comes with an example configuration file that you should copy into the place where the MPD service can find it. It likes to be in /etc/mpd.conf
]# cp /usr/share/doc/mpd-0.13.0/mpdconf.example /etc/mpd.conf

Make a directory locally to hold the MPD metadata like playlists, the MPD database file, and the logs. I thing /var is a good place for that kind of thing...
]#mkdir /var/mpd
Edit the MPD configuration file to tell MPD where to find the music and where to keep its metadata.

]#vi /etc/mpd.conf

(The paths here should be set to where we created them earlier.)

######################## REQUIRED PATHS ########################
music_directory                 "/usr/local/music"
playlist_directory              "/var/mpd/"
db_file                         "/var/mpd/mpd.db"
log_file                        "/var/mpd/mpd.log"
error_file                      "/var/mpd/mpd.error"
################################################################

(It is a good idea to uncomment the next two options in case you need to do any troubleshooting.)

######################## OPTIONAL PATHS ########################
#
# If you wish to use mpd --kill to stop MPD, then you must
# specify a file here in which to store MPD's process ID.
#
pid_file                        "/var/mpd/mpd.pid"
#
# If specified, MPD will save its current state (playlist,
# current song, playing/paused, etc.) at exit.  This will be
# used to restore the session the next time it is run.
#
state_file                      "/var/mpd/mpdstate"
#
################################################################

(This section should be edited only if you don't hear anything later on.)

########################## AUDIO OUTPUT ########################
#
# MPD supports many audio output types, as well as playing
# through multiple audio outputs at the same time.  You can
# specify one or more here.  If you don't specify any, MPD will
# automatically scan for a usable audio output.
#
# See 
# for examples of other audio outputs.
#
# An example of an ALSA output:
#
audio_output {
        type                    "alsa"
        name                    "My ALSA Device"
#        device                  "hw:0,0"     # optional
#        format                  "44100:16:2" # optional
}
#

(As above, only edit this is you have no music when you test your web front end.)

############################# MIXER ############################
#
# MPD needs to know what mixer settings to change when you
# adjust the volume.  If you don't specify one here, MPD will
# pick one based on which ones it was compiled with support for.
#
# An example for controlling an ALSA mixer:
#
mixer_type                      "alsa"
mixer_device                    "alsamixer"
mixer_control                   "PCM"

Create the MPD database:
]# mpd --create-db &

(Wait a while!)

Start MPD:
]# service mpd start

Make sure MPD will start when you reboot:
]# chkconfig --level 3 mpd on

ADVANCED: Schedule Nightly MPD Database Rebuild

I use a Podcatcher to grab podcasts like This American Life and the MAKE podcasts. When files are added, changed, or removed, the MPD server does not know about it until its database is rebuilt. In order to keep up with podcasts, we can add a cron job to rebuild the database nightly while we rest. The command to add a cron job is:
]# crontab -e
3 4 * * * /usr/local/bin/mpd --create-db > /dev/null 2>&1

That line tells the server to run that command at 4:03 a.m. every night of every week. You can see the command mpd --create-db; the rest of that line tells the server to suppress all output so we don't get an email every night listing ALL of the music files in our library.

START THE WEB SERVER

Make sure the web server will start after a reboot with this command:
]# chkconfig httpd on

Start the server with this command:
]# service httpd start

Starting httpd:                                            [  OK  ]

DISABLE FIREWALL

By default, Fedora provides you with a very restrictive firewall. You need to allow access to your web server, and you really don't need a firewall if this server is not going to be accessible from the internet. (It's not, right? Because if it is, you have more reading to do!)
Remove the firewall service from starting automatically with this command:
]# chkconfig iptables off
This command removes all firewalling immediately:
]# iptables -F
And this command stops any firewall process:
]# service iptables stop

Flushing firewall rules:                                   [  OK  ]
Setting chains to policy ACCEPT: filter                    [  OK  ]
Unloading iptables modules:                                [  OK  ]

USE PITCHFORK AS YOUR WEB PAGE CONTROL

MPD is the "server," and there are many clients available for it. It seems like most clients want to play their music from a server locally on a laptop. That is called "streaming." My desire is to play the music right there on the server so the music comes out of the sound card on the server resulting in music from my stereo all over the house. Use http://mpd.wikia.com/wiki/Clients for a list of ALL the clients.

Pitchfork is one MPD client that is written using Ajax and has themes. It is a nice interface.
The current release is:
http://pitchfork.remiss.org/files/pitchfork-0.5.4.tar.bz2
So use wget to download it to the server
]# cd /tmp
]# wget http://pitchfork.remiss.org/files/pitchfork-0.5.4.tar.bz2
]# tar -xjf pitchfork-0.5.4.tar.bz2
]# cp -r pitchfork-0.5.4/* /var/www/html
]# cd /var/www/html

Read the INSTALL file which contains the instructions for installation and configuration.

  1. Put either the pitchfork.conf or pitchfork_domain.conf file, found in this doc/ directory, in /etc/http/conf.d (or where your extra config-files are) and make sure they specify the correct directories for pitchfork.
    ]# cp doc/pitchfork.conf /etc/httpd/conf.d/
    ]# vi /etc/httpd/conf.d/pitchfork.conf

    Change these 2 lines from:
    Alias /pitchfork /var/www/pitchfork

    to:
    Alias /pitchfork /var/www/html
  2. Apache needs to have write access to the config directory:
    • Go to where you installed pitchfork
    • chown apache config

    ]# cd /var/www/html
    ]# chown apache config

  3. Reload/restart apache:
    ]# service httpd restart
    Stopping httpd:                                            [  OK  ]
    Starting httpd:                                            [  OK  ]
  4. Point your web browser to your server to test the web interface: http://192.168.0.10/

    You should see the setup page for pitchfork. Probably everything can be left as default. Just click "Save" and you should be presented with your new stereo system! Choose some songs and play them!

    MISC COMMENTS

    The web server has what it calls the "root"; this means where it starts serving pages from if you don't put anything after the web server address. So if you put http://192.168.0.10 in your address bar, then the web server gives you the default page from /var/www/html by default. If you put your web control panel files into /var/www/html/pitchfork then you have to put http://192.168.0.10/pitchfork into the address bar to get to your controls. This allows you to try different web front ends by putting them into different directories.

    + LINKS

Join the conversation -- every MAKE article has an online page that includes a place for discussion. We've made these RSS and Atom feeds to help you watch the discussions: subscribe.