Playing music on a Raspberry Pi using UPnP and DLNA (v3)

Posted in Posted on 2014-05-11 14:05

Playing music on a Raspberry Pi using UPnP and DLNA (v3)

What we are aiming for

A music system with a Raspberry Pi plugged in to an amplifier playing music that you choose with your mobile phone. The music can come from MP3s on your phone, from files on your server, files “in the cloud” or from internet radio stations. If there’s more than one Android phone in your household you can have them all synchronised, showing the same playlist and controlling the same music. If you have multiple Raspberry Pis you can put one in each room and choose which one to play the music with. This is all achieved with free software and open standards. I’ve just written some instructions to show how to do it.

I have blogged on this topic two times previously (here and here). Each time it gets simpler as the Raspberry Pi eco-system evolves. I needed a new Raspberry Pi UPnP renderer to be attached to an amplifier and speakers.

My previous post explains lots more about how the system as a whole works, how to test it and how you control the music. This post merely updates the instructions for installing gmediarender and includes some info on using a USB sound card.

Setting up a Raspberry Pi to be a UPnP media renderer

Installing the base operating system

As usual I started from the latest Raspbian distribution (2014-01-07) which needs a 4GB SDCard card apparently. Once the Raspberry Pi is up and running and on the network, log in (user: “pi”, password “raspberry”), run the first-time configuration command and then update to the very latest firmware. These following commands also show the before and after versions in case that is useful for people:

$ uname -a
Linux raspberrypi 3.10.25+ #622 PREEMPT Fri Jan 3 18:41:00 GMT 2014 armv6l GNU/Linux
$ sudo raspi-config
$ sudo apt-get install rpi-update
$ sudo shutdown -r now

Once it has rebooted, log in again check the new status and upgrade all the installed packages:

$ uname -a
Linux raspberrypi 3.12.19+ #681 PREEMPT Fri May 9 16:36:10 BST 2014 armv6l GNU/Linux
$ /opt/vc/bin/vcgencmd version
May 9 2014 16:52:52
Copyright (c) 2012 Broadcom
version c8ed097f7c23249e702bea3ed6b5720136ba00e4 (tainted) (release)
$ sudo apt-get update
$ sudo apt-get upgrade

Installing gstreamer 1.0

Henner Zeller has made the gmrender-resurrect UPnP renderer and it is known to work best with gstreamer 1.0. Unfortunately Raspbian currently still comes with gstreamer 0.10. Fortunately, Christi Scarborough has compiled the necessary gstreamer 1.0 packages for the Raspberry Pi and provided them as debian packages. She has documented it all and very honestly included the warning that using these packages means you have to trust her not to have slipped in some malware or something. Some of the instructions on this page are just a duplication of hers. Christi also provides a ready-made build of gmediarender but as I wasn’t sure which version that was, I wanted to use Henner’s directly.

First we have to install Christi’s GPG key to show that we trust her packages:

$ sudo wget -O -[email protected] \
| sudo apt-key add -

Then, using “vi”, “nano” or whatever, create a new file to hold the address of Christi’s Debian repository, call it /etc/apt/sources.list.d/upnprender.list and add just one line: deb wheezy main

We then need to update the local cache of available packages to include Christi’s packages and then follow Henner’s instructions for installing gmrender-resurrect:

$ sudo apt-get update
$ sudo apt-get install libupnp-dev libgstreamer1.0-dev \
gstreamer1.0-plugins-base gstreamer1.0-plugins-good \
gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly \

Installing gmediarender

Continuing with Henner’s instructions:

$ cd
$ git clone
$ cd gmrender-resurrect
$ sudo apt-get install autoconf
$ ./
$ ./configure
$ sudo make install

This puts gmediarender into /usr/local/bin and a couple of icons into /usr/local/share/gmediarender

Henner has provided an init script to start and stop the gmediarender software, so we’ll copy this into the appropriate place:

$ sudo cp scripts/init.d/gmediarenderer /etc/init.d

Edit the init script if you need to (e.g. set the name of the renderer). Then use the update-rc.d command to put in the necessary symbolic links to the init script that start or stop the service at different runlevels (the following ls command shows these for interest):

$ sudo update-rc.d gmediarenderer defaults
$ ls -l /etc/rc*.d/*gmed*
lrwxrwxrwx 1 root root 24 May 10 11:03 /etc/rc0.d/K01gmediarenderer -> ../init.d/gmediarenderer
lrwxrwxrwx 1 root root 24 May 10 11:03 /etc/rc1.d/K01gmediarenderer -> ../init.d/gmediarenderer
lrwxrwxrwx 1 root root 24 May 10 11:03 /etc/rc2.d/S04gmediarenderer -> ../init.d/gmediarenderer
lrwxrwxrwx 1 root root 24 May 10 11:03 /etc/rc3.d/S04gmediarenderer -> ../init.d/gmediarenderer
lrwxrwxrwx 1 root root 24 May 10 11:03 /etc/rc4.d/S04gmediarenderer -> ../init.d/gmediarenderer
lrwxrwxrwx 1 root root 24 May 10 11:03 /etc/rc5.d/S04gmediarenderer -> ../init.d/gmediarenderer
lrwxrwxrwx 1 root root 24 May 10 11:03 /etc/rc6.d/K01gmediarenderer -> ../init.d/gmediarenderer

Rebooting now should give us a system with gmediarender running, which we can test with ps:

$ sudo shutdown -r now
(wait a bit and log in again)
$ ps aux|grep gmed
pi 2078 15.5 9.1 198996 40828 ? Ssl 11:05 0:05 /usr/local/bin/gmediarender -f Garden -d -u  bd1dcf3e746aa69812943cb1d00f7ebc --gstout-audiosink=alsasink --gstout-audiodevice=sysdefault --gstout-initial-volume-db=-10
pi 2123 0.0 0.1 3548 800 pts/0 S+ 11:06 0:00 grep --color=auto gmed

Using a USB audio card

Basically it all works at this point, though using the built-in audio output of the Raspberry Pi never gives a great quality sound. There are various really interesting high quality DAC cards now available for the RPi which connect directly to the circuit board but for now I went for the simple option of getting a dirt-cheap USB audio card (for 99p you can’t really go wrong…). It does sound much better than the built-in output and is automatically picked up by the latest Raspbian version.

Plug in your USB audio card (which can cause the RPi to reboot…) and then set it up by following an Adafruit tutorial.

I have a CM109 chipset so all I had to do was edit /etc/modprobe.d/alsa-base.conf and change options snd-usb-audio index=-2 to options snd-usb-audio index=0

Reboot again and decent sound comes out of the USB sound card!


Comments powered by Disqus