RPMPD - Raspberry Pi Music Player Daemon

Construct your own Sonos-type music system for a fraction of the price.

Yes, here is yet another webpage on how to setup your Rasperry Pi as a music server. :)

(This one is probably the easiest to implement for non-technical folk. No soldering, no programming, etc.)

Here are the out-of-the-box features of this one:

Table of Contents

Step 1 : Buy the Parts
Step 2 : Prepare the SD Card
Step 3 : Assembly
Step 4 : Wireless Network Configuration
Step 5 : Software Configuration
Step 6 : Share Your Music
Step 7 : Test RPMPD - Raspberry Pi Music Player Daemon
Step 8 : Test the Remote Control/Keypad Functionality
Obtaining Streaming URL for iHeartRadio Channels
Closing Thoughts

Step 1 : Buy the Parts

That's for a complete, out-of-the-box solution when you don't have any of the parts listed above already laying around (e.g. sdcard, hdmi cable, usb hub, extension cord, speakers, etc)

If you just want a headless server without keypad/remote and you have most of the things above, you could probably cut this down to just:

pi + case + power adaptor + sdcard = $55.02 (plus another $10 if you need the wireless adaptor)

Note that I went through the Raspberry Pi Hardware Compatibility List to ensure that I was getting compatible parts. I'm still not happy about the price of the powered USB hub ($17.49), but I chose one that appeared to be the least expensive of the ones that are noted to work well. If anyone tries this setup and knows of a less expensive option for any of the items listed (and can confirm that it works flawlessly) then please let me know!

You'll also probably want some kind of case or enclosure to hold all the pieces and wires together in a tight package. My first pass was a $0.00 solution where I used one of the shipping boxes:

Unbeknownst to me, however, this was "ugly". My beautiful/wonderful wife brought that to my attention so the end result is now the picture at the top of the page.

Step 2 : Prepare the SD Card

Download the RaspMPD Custom Raspbian MPD Image

Note that Google indicates that they can't scan the file for viruses because it's too big, but you can "Download anyway". I have zero interest in turning a handful of Raspberry Pis into spambots, so you can probably rest easy on this one. :)

Write the image to your SD card

Step 3 : Assembly

Unpack your Pi and attach the peripherals before putting it in the case - it's much easier than trying to gently/nimbly do so after putting it in the case.

Here is a picture of everything attached:

Here is a picture after it has been put in the case:

Plug the extension cord into the wall and after about two minutes it should be fully started.

Note - if you can attach an RJ-45 network cable to your Pi to directly attach it to the network, you don't need to attach the HDMI cable or the USB keyboard. You should be able to immediately login remotely to perform the rest of the configuration and you can skip to Step 5 : Software Configuration You can also attach the USB keypad now if you intend to use one.

Step 4 : Wireless Network Configuration

Login at the console with:

Username: pi
Password: raspberry
Change to the root user by entering this command:

sudo su -
Generate the wireless network configuration settings by running the following command:

wpa_passphrase SSID PASSWORD
Replace SSID with your wireless network SSID and replace PASSWORD with your wireless network password. Here is some sample output from the command:

root@raspberrypi:~# wpa_passphrase myssid mypassword
network={
	ssid="myssid"
	#psk="mypassword"
	psk=2f0568b3492812bd56b946dbaf3fd7dd669b9a4602a09aa6462ff057949b025c
}
Add this data to the network interface file:

joe /etc/network/interfaces
Replace the values of wpa-ssid and wpa-psk with the ssid and psk values from the previous command. In the above example, the interfaces file would now look like:

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet dhcp
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
  wpa-ssid "myssid"
#psk="mypassword"
  wpa-psk 2f0568b3492812bd56b946dbaf3fd7dd669b9a4602a09aa6462ff057949b025c

iface default inet dhcp
Press Control-K and then X to save the changes and exit joe. Press Control-C if you want to exit joe without saving your changes.

Issue this command to reboot the Pi and have the wireless settings take effect:

reboot
You should no longer need your HDMI cable or the USB keyboard attached to the Pi. You should be able to remotely login like so:

ssh pi@pi.local
Also note that you can now attach the USB keypad if you intended to use one.

Step 5 : Software Configuration

Remember to change to root before performing any of these configurations:

sudo su -
Turn on the speaker and issue the following command to verify that the audio works:

aplay /usr/share/sounds/alsa/Front_Right.wav
A lady's voice should say "Front, Right"

Assign a meaningful hostname to your Pi by running the following:

joe /etc/avahi/avahi-daemon.conf
Look for the following section near the top:

[server]
host-name=pi
Change "pi" to whatever you want your pi to be named. For example, if you change it to this:

[server]
host-name=livingroom
Then your Pi's new hostname would be "livingroom.local". Run the following for the change to take effect:

/etc/init.d/avahi-daemon restart
If you have multiple Raspberry Pi music servers, then you can give each one a unique hostname and also a unique mpd service name for uPNP clients. Assign your mpd service a unique uPNP name by running the following:

joe /etc/mpd.conf
Look for this section:

zeroconf_name                   "Music Player - Raspberry Pi"
Change it to whatever you want and then run the following for the change to take effect:

/etc/init.d/mpd restart
If you will be using HDMI audio output, you will need to do the following:

joe /etc/rc.local
look for

sudo amixer cset numid=3 1
Change 1 to 2 for HDMI audio. That will ensure the output is correct across reboots. Run the following command to make the change in the running instance:

amixer cset numid=3 2

Step 6 : Share Your Music

The mpd service is setup to read music files from:
/mnt/music
You could copy all of your music files to that directory if your SD card is large enough, but it's probably more likely that you'll want to read the music files from a different server. There are a few preconfigured ways to do this.

uPNP

You could use any number of free/commercial products to setup a uPnP media service. Click here for a comparison list of the various uPnP options.

Once you have your uPnP server setup, do the following on your Pi:

joe /etc/rc.local
And uncomment the following line (remove the # character at the beginning of the line):

#sudo djmount -o allow_other /mnt/music
That will ensure the djmount service runs during reboots. Run the following command to make the change take effect immediately:

djmount -o allow_other /mnt/music
djmount is a nifty program that will mount all discovered uPnp servers as a regular file system. So all of the files that you're sharing on your uPnP server will just appear under /mnt/music.

Windows Shared Folders/Samba

If you are sharing your drives/folders via Windows Sharing or Samba, then you can edit rc.local like so:

joe /etc/rc.local
and add the following line to the end:

sudo mount -t cifs -o user=USERNAME,password=SECRET //192.168.1.210/MYSHARENAME /mnt/music
Replace USERNAME with the user name that has access to the share.
Replace SECRET with their password.
Replace 192.168.1.210 with the IP address or hostname of the computer that is sharing the files.
Replace MYSHARENAME with the name of the share.
Editing rc.local will ensure the mount happens across reboots. You'll also need to run it manually for the change to be immediately visible:

mount -t cifs -o user=USERNAME,password=SECRET //192.168.1.210/MYSHARENAME /mnt/music

NFS - Network File System

A common way to share files on Unix-based systems is via NFS. Setting up an NFS server is outside of the scope of this article, but if you google for "setup nfs server" you'll find lots of articles to help. In order to make your NFS-shared files visible on your Pi, you'll need to edit rc.local:

joe /etc/rc.local
and uncomment this line (remove the # from the beginning of the line):

sudo mount -t nfs -o nolock 192.168.1.210:/mnt/b/mp3 /mnt/music
Replace 192.168.1.210 with the IP address or hostname of your NFS server.
Replace /mnt/b/mp3 with the directory you are sharing on your NFS server.
Changing rc.local will ensure the NFS share is mounted across reboots. To make the change immediately visible, run the following:

mount -t nfs -o nolock 192.168.1.210:/mnt/b/mp3 /mnt/music

Step 7 : Test RPMPD - Raspberry Pi Music Player Daemon

Once your music files are visible to your Pi, the first thing you'll want to do is make mpd update its database so that you can search for songs, add them to the playing queue, and create playlists.

Click here for a list of MPD Clients

Each client should have a way to "update database". If you have a large collection then the initial update could take a couple of hours. Future updates, however, just look for changes and will generally take less than a minute. Once that completes (or even while it's performing the update) you can add songs to the playing queue and start listening to music.

There is also a web server running on the Pi which serves up a very basic client interface. I looked at a number of web-based clients, but they all had problems of some sort (slow/cumbersome, lack of major browser support, etc). This interface should work on every browser on every pc or mobile device. However, it lacks more sophisticated functionality like creating/managing playlists or changing the play queue. My intention was for it to be more like a simple remote control that would work on any device. There are a host of device-specific clients (iPad specific, Android, Windows/Linux, etc) that do more if you need that. You can access the Pi web server by opening the hostname in a web browser. The default is:

http://pi.local
but if you changed the avahi hostname in Step 5 : Software Configuration, then you would need to use that hostname instead.

Step 8 : Test the Remote Control/Keypad Functionality

There is a program that runs at /opt/mpckbd/mpckbd that detects keystrokes and translates them into commands to control mpd. This works with both the keypad and the MCE remote since the remote is actually just a kind of wireless keyboard. Here are the current control mappings:

Remote Button Keypad Key Function
Play Enter Toggle Play/Pause
>>|
Chan+
* Next Track
|<<
Chan-
/ Prev Track
Vol+ + Volume Up
Vol- - Volume Down
Back Arrow Backspace Set Volume to 50%
Yellow Toggle Repeat Mode
Blue Toggle Random Mode
1 1 Play Playlist Named plist1
2 2 Play Playlist Named plist2
3 3 Play Playlist Named plist3
4 4 Play Playlist Named plist4
5 5 Play Playlist Named plist5
6 6 Play Playlist Named plist6
7 7 Play Playlist Named plist7
8 8 Play Playlist Named plist8
9 9 Play Playlist Named plist9
0 0 Run Script on Pi Named
/bin/svenfavs.sh

I noted a problem during testing of a fresh install where the remote control and keypad were non-responsive. Restarting the mpckbd programs did not solve the problem, but rebooting the Pi did. I think this was the result of plugging/unplugging the USB peripherals while the Pi was running. I have not been able to reproduce the issue, so if you note this, just plug in all of the USB peripherals you want to use, reboot the Pi, and it should be fine.

Obtaining Streaming URL for iHeartRadio Channels

I've seen many, many forum posts on how to get the underlying streaming URL for Internet radio station hosted by places like iHeartRadio, so here's a simple tutorial. First visit iHeartRadio Station Search to search for a station you want to hear. If you click on one of the search results (or hover over the link url and look at it) you'll see the URL looks like this:

http://www.iheart.com/#/live/Big-1003-2505/
Note the four-digit number at the very end. In this case, it's 2505. Now run the following on your Pi:

wget -q --post-data='' 'http://www.iheart.com/a/live/station/####/stream/' \
-O - | python -mjson.tool | grep shoutcast_url
Replace #### with the four-digit number of your station. This will give you the streaming url that you can directly add to mpd's playing queue. Note that if the streaming URL ends in .pls then do the following to get the real stream:

#For example:
wget -q -O - http://playerservices.streamtheworld.com/pls/WCHZFMAAC.pls | grep \:80

Closing Thoughts

The only thing I'm not crazy about with this is the notorious popping sound shortly after pausing or after playing from a paused mode. Click here to read some forum posts about the subject. The thread is fairly recent so perhaps if/when a solution is found, it will be posted there. I've tried everything noted in that thread up to the November 15th posting but nothing completely alleviated the popping noise in all test cases. This only happens with the analog audio port and not over HDMI, though, so anyone who's looking to drive 300w speakers might want to look into connecting the Pi to a receiver that takes HDMI inputs. The analog out is well suited for casual installations, however, such as in a bathroom or kitchen.

If anyone has any comments/suggestions I'd love to hear them. Click here to contact me.