Why DLNA?

The goal is simple: make Raspberry Pi play music remotely. Technically this can be already accomplished with what I described in the pulseaudio article, but that solution has several drawbacks. The DLNA way provides a different approach, with the following advantages:

playback from any OS/device (not just Linux/UNIX with pulseaudio sending an audio stream), eg. some Windows or smart TV

playback control from your phone/tablet/etc

independent playing device, controlling device, and media storage device (any independence of these if required)

DLNA concepts

Before I dive into configuration let me first clarify some basics on what DLNA/UPnP is all about. In short, DLNA is the functionality, and UPnP is the underlying communications mechanism used in a local network. While I’ll skip the latter, the former could be shortly described as a way multimedia is managed between independent devices. Basic use cases consist of three major DLNA roles:

DLNA media server – there is a device storing your files somewhere on your (W)LAN. This might be your NAS with DLNA capabilities, or a computer with appropriate software configured and running (good fit for Raspberry Pi)

DLNA controller – to manage the playback of your media, seek, skip, pause, and track time you need a controller. This is where you press PLAY🙂

DLNA renderer – in the end you need to actually watch or listen to the media. This is where you have a display and/or speakers connected (also a good fit for the Pi)

Sometimes there is also DLNA player mentioned – combining controller and renderer together as one entity. Below I focus on two of these roles; controller is omitted here.

DLNA Renderer

As of today (March 2013), there are not many choices in terms of software for providing this capability. There seem to be larger projects providing this functionality (as far as I remember: XBMC possibly via Raspbmc or OpenELEC), but adhering to the traditional UNIX philosophy of small utilities for well-defined tasks, I skipped these. Some time ago GMediaRender project was being developed, which would suit audio just fine, but currently it is a bit buggy and not really usable in production. Luckily Henner Zeller decided to resurrect the code forking it to gmrender-resurrect – which works just great.

It is a project in development, which currently needs to be acquired from github directly. Let’s get build and run dependencies:

You should now see it starting up, registering for various mime media types, and finally saying:

Ready for rendering..

Note: If you plan to run a few of these on one local network (as I happen to do) you might seriously consider using -u command line switch to specify renderer’s UUID. For example, to derive one from Ethernet’s MAC address:

For starting it up on boot you can either write an init script, or add these commands to /etc/rc.local – with the last one single-quoted in a su call like this:

su - pi -c '(...)' >/dev/null &

Now on to the media server. If you need just the renderer you can skip that – these can be installed independently.

DLNA Media Server

It looks like the minidlna server implementation (small programs for well-defined tasks, remember?) is in Raspbian repositories:

$ sudo aptitude -P install minidlna

The configuration is pretty straightforward in /etc/minidlna.conf – just set your media_dir as explained in the comments to the path(s) where your media is mounted. You could also change friendly_name to RaspberryPi and serial to some unique value if required. To start just use the init script provided:

$ sudo /etc/init.d/minidlna start

On its first run it will start indexing your files and building database. Give it some time to complete. And off to testing🙂

Testing Raspberry Pi DLNA operation

Get your controller, and browse the network. Whether it is your TV, some Windows software, or BubbleUPnP on Android you should see your renderer and/or media server on the network. Here’s an example from BubbleUPnP:

As far as I recall, on Windows you can right-click a local file and select “Play To”, and Raspberry Pi should be there as a renderer for you to pick. Do not be discouraged if the playback fails, it might be not your fault, since Windows Media Player requires the file to be in its library, and you need to set-up WMP to allow access, etc. Personally I had mixed results with this.

Notes

You might not notice it at first, but DLNA is not only about local media. The renderer can also play media streamed from outside, eg. internet radio. If your controller allows you to play an URL, you might try pasting to it something from shoutcast.com (BubbleUPnP and XiiaLive do this together perfectly and automatically on Android).

If you get popping and clicking sound while changing songs, check if your Raspberry Pi’s audio device is kept open playing silence – my earlier article covers this issue.

Like this:

Related

Hi – im try to using your How To do on my Pi – but after cloning the GIT the “./configure –prefix=$HOME/opt/gmrender-resurrect && make install” dont work – if i look at the Directory – there is no “configure” within there ?
What i making wrong ?

Hi Peter! I have just checked my setup and I could not observe the issue you are describing with neither manual/automatic song change. I am currently running commit 0a8f9c495ebde88680c69e69e045636f04b01b8e of gmrender-resurrect on my Pi. Might be the audio device reopening. Did you try pulseaudio/pacat combination to keep the audio device open playing silence, and gmrender going through pulseaudio?

Hi, great article! I’m currently struggling to run all that on my MK802 miniPC.
But the question is: is it possible to stream same audio on multiple devices simultaneously using DLNA and gmrender-resurrect?
Thanks!

I am not sure what you want to achieve… Did not explore running multipoint DLNA; I am not even sure if it has any chance to work without audio synchronization issues between the nodes. What exactly would you like to do?

Thanks for response!
The plan is: to have several DLNA-renders in different rooms, playing same music, and controlled with a single control device.
I found as well this:http://www.bubblesoftapps.com/bubbleupnpserver/
might help with a single device control.
but I’m not sure about synchronization.
Thought you might have done something similar.
I know that pulseaudio has such functionality but not sure about DLNA.
Cheers!

Hi, this is exactly what I am doing at my place, except it is not with DLNA, but pulseaudio. As far as I understand DLNA, on play command the player gets an URL of media to be played, connects, and starts. Taking this architecture into account I doubt if there is any additional way of synchronizing playback between them. Surely you can command 3 players to play one resource, but they can start with delays (sec-msec), and then go out of sync over 1h of playback anyway (quartz differences). The thing is, that pulseaudio compensates this as best as it can. It may not be always ideal, sound devices may vary on the network in terms of buffer sizes… The out of sync effect is especially audible when you are in the center and hear every device equally.

It’s just that I have Synology NAS Server running DLNA, and I’d like to use it as multimedia server. From what I’m aware of there is no possibility to set it as pulseaudio server, and therefor I have to stick with DLNA. So I thought maybe gmrender-resurrect supports renders synchronization. If not, I’ll probably just stick with AirPlay from apple, as Synology runs iTunes server from box. More cash but less troubles though…

Hmm, you might try playing on a DLNA player media from your NAS, and the player would play to local pulseaudio device, and pulseaudio would play to the network (and other pulses). You might want to try this out. But Synology NAS Server runs linux, right? You could consider doing research on installing pulseaudio on it🙂 If it is a player.

Is there a way to turn autompd off (remove the proilfe permanently)? For some reason gmpc changes to it automaticly sometimes (seems pretty random). Then it tries to index everything (cpu hogging) in my home folder.Autompd is defiantly a great idea, but old mpd users will not appreciate it.

Hello, thanks for the great guide. I’ve a doubt about what have i to install to play music files from xbmc to one wifi speaker (Pioneer A4 XW-SMA4-K). Thanks a lot for the answer and congratulations for the blog.