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:
- Raspbian image with all necessary software pre-installed and 99% pre-configured
- Integrated web server to control your RPMPD via a web browser
- Control RPMPD via keyboard keystrokes (for example, press "1" to start playing a stored playlist)
- Control RPMPD via a remote control
- Custom built MPD:
- Uses newest FFMPEG 1.0.1 libraries
- Patch to allow ffmpeg plugin to decode internet radio streams (libfaad was behaving poorly)
- Patch to parse malformed internet radio stream tags to extract the artist/name on akamaistream.net streams
- MPD configured to reduce the dreaded "popping" noise - the pop will now only be heard occasionlly when pausing/unpausing. No pops when changing tracks.
- Avahi pre-installed so upon first boot you can simply "ssh firstname.lastname@example.org" to login. No need to try and figure out what the IP address is anymore.
- djmount, NFS, and SMB clients pre-installed so you can quickly get your music library shared to your Pi
Table of Contents
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.
Insert SD card
Attach power adaptor
Insert wireless USB dongle in bottom USB port
Unpack the USB hub - you do not need the attachment that adds four more ports. Attach the power adaptor and mini-USB cable to the USB hub. Attach the other end of the USB cable to the top USB port on the Pi.
Unpack the remote and install the batteries. Attach the IR receiver to one of the USB hub ports.
Unpack the mini speaker. Attach the mini-USB cable to the speaker. The other end of the cord has two plugs. You can separate the ends another few inches by carefully/gently pulling them apart. Insert the 3.5 audio jack into the Pi and insert the USB end into one of the ports of the USB hub.
Attach one end of HDMI cable to the HDMI port on the Pi and the other end to a monitor or TV (Not pictured because my monitor is too far away and I'm too lazy to unplug the cable from my monitor :)
Attach USB keyboard to one of the USB hub ports.
Plug the USB hub and the Pi AC adaptor into the extension cord
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:
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
Add this data to the network interface file:
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:
iface lo inet loopback
iface eth0 inet dhcp
iface wlan0 inet dhcp
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:
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:
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:
A lady's voice should say "Front, Right"
Assign a meaningful hostname to your Pi by running the following:
Look for the following section near the top:
Change "pi" to whatever you want your pi to be named. For example, if you change it to this:
Then your Pi's new hostname would be "livingroom.local". Run the following for the change to take effect:
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:
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:
If you will be using HDMI audio output, you will need to do the following:
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:
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.
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:
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:
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:
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:
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:
||Set Volume to 50%
||Toggle Repeat Mode
||Toggle Random Mode
||Play Playlist Named plist1
||Play Playlist Named plist2
||Play Playlist Named plist3
||Play Playlist Named plist4
||Play Playlist Named plist5
||Play Playlist Named plist6
||Play Playlist Named plist7
||Play Playlist Named plist8
||Play Playlist Named plist9
||Run Script on Pi Named
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:
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:
wget -q -O - http://playerservices.streamtheworld.com/pls/WCHZFMAAC.pls | grep \:80
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.