Raspberry Pi Remote Control Music Player
All it takes is a few simple steps to turn a Raspberry Pi into a remote control music player.
Music Player Daemon (mpd) is an incredibly flexible piece of software for playing digital music from local storage and Internet radio, and which boasts a wide selection of client applications that can be used to remotely control it and manage playlists etc. This blog post looks at a basic configuration for playing local MP3 files and example remote control via an Android application.
The steps outlined here assume a Raspbian wheezy install, and I had a USB wireless network adapter configured and used the Raspberry Pi “headless” (without a monitor).
Installing The Software
When setting up mpd on a Raspberry Pi it’s advisable to also install the command line client software, mpc, along with the Avahi mdns (zeroconf) software. This can be done with the command:
$ sudo apt-get install avahi-daemon mpd mpc
Multicast DNS (mdns)
The Avahi software is just for convenience and makes it possible to connect to a Raspberry Pi that uses DHCP for its network configuration by hostname instead of using an IP address. For example, to ssh to the Pi I have set up as a music player I use:
$ ssh email@example.com
In this case I had set the hostname of the Pi to be “hifi”, and the “.local” suffix denotes that I want the name to be looked up via mdns/zeroconf.
It may also be necessary to set up mdns resolution on the client machine, e.g. a desktop. Under Debian this can be done by installing the mdns name service library via:
$ sudo apt-get install libnss-mdns
And to then also ensure that nsswitch.conf is configured appropriately. The file on my Debian laptop contains the hosts line:
hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4
An alternative to using mdns/zeroconf would be to configure the Pi to use a static IP address, either by setting one up in /etc/network/interfaces or by configuring the home network router to always allocate the same DHCP address to the Pi.
The mpd software is configured via the file /etc/mpd.conf.
In order to allow remote clients to connect over the network its necessary to comment out the line starting bind_to_address.
Removing the comment from the line containing auto_update should enable auto updating of the mpd library whenever new music files are added.
Removing the comment from lines with zeroconf_enabled and zeroconf_name will mean that the Pi will advertise it’s music player services to any zeroconf aware clients. As previously mentioned, mpd is incredibly flexible and there are plenty of other configuration options that can be set, but it’s best to start out simple and experiment with more advanced options once you have a basic working setup. On completion of editing mpd.conf its necessary to restart mpd:
$ sudo service mpd restart
The Command Line Client
Music files should be copied to /var/lib/mpd/music, and once this has been done the mpc command line client can be used to tell mpd to update the library:
$ mpc update
Following you can check to see if the library has been updated with:
$ mpc ls
The command line client can also be used to check the status of mpd, search the library, manage playlists and pause and play music etc, and is particularly useful when testing the setup.
The MPDroid software for the Android platform is just one of many client applications that can be used to remotely control mpd over a network connection. Unfortunately Android doesn’t appear to support mdns/zeroconf, and so when configuring MPDroid its necessary to enter the IP address for the mpd server. This can be ascertained from a machine that does support mdns by using ping, e.g.:
$ ping hifi.local
Although in practice if you were going to be using a non-mdns aware client most of the time it would make sense to configure the Pi with a static IP address. The many other clients that can be used to enable remote control include web applications that can be installed on the Pi alongside mpd, thereby removing the need to install software on remote machines.
As others have noted the quality of the Raspberry Pi’s built in audio output isn’t fantastic, and if you were using this as an everyday music player it would be worth investing in USB sound hardware, which can be picked up for as little as a few pounds.
The Raspberry Pi driving a pair of valve amplifiers via a simple attenuator (dual potentiometer fitted in a small aluminium case next to the turntable). The larger acrylic case to the bottom of the image houses a phono pre-amplifier.
With the addition of a USB network adapter and sound hardware the Raspberry Pi makes a great network music player that brings the unprecedented flexibility afforded by open source technology, and the basic setup described here could be extended to also, for example:
- Play music files from a remote NAS drive or desktop mounted via NFS/Samba
- Enable streaming music to a remote client using mpd’s built-in httpd
- Enable mpd control via buttons/dials connected to GPIO
- Enable streaming music to the Pi from Apple’s iTunes via ShairPort