Early in 2014, I finally got around to turning my Raspberry Pi in to a little XMBC media centre by installing Raspbmc. Which was fun. And also easy.
Perhaps a little too easy: I’m a bit of a nerd, so it didn’t take long to get bored of just playing regular type media off the external hard drive. Part of the reason I have a Raspberry Pi, is for the fun of thinking of what relatively useless thing I might potentially do with it next, and then spending (wasting?) many hours trying to do it.
So, as I was trying to decide what to do next, I considered the fact that I fairly often like to play music on my PC while I’m working. And my sound system is now hooked up to the Raspberry Pi. So it would be most convenient if I could just deliver the sound across my network for Raspbmc to play for me. I was running Ubuntu 13.10 – Saucy Salamander – at the time.
This turned out to be a lot harder than you might imagine. Excellent. (Disclaimer: this was in 2014 – I suppose it might be easier now … if so, I apologise for the convenience).
Option 1: PulseAudio Network Streaming
Ubuntu uses PulseAudio by default for soundy things. So that is where I started my quest. If you pop open paprefs (installing it first, if it’s not there), you will notice that it claims to be able to do things over a network.
Here is a link to the incomprehensible documentation about it: NetworkSetup. At least, it was incomprehensible when I first read it. It now makes a little bit more sense – but I assume that you are at the start of your journey if you are even reading this – so it probably won’t make much sense to you. Alternatively you could have a read of this blog that claims to make network audio with PulseAudio (somewhat) easy.
However, I decided to abandon this idea:
- Raspbmc doesn’t install with PulseAudio by default – and you would need it to be running in server mode – and at time of writing the people of the internet seemed to be having some trouble getting them to play together.
- I wanted something that was more integrated with the XMBC user interface – rather than just something running in parallel.
Option 2: Apple AirPlay
Perhaps, like me, you noticed that paprefs has greyed-out option: “Make discoverable Apple AirTunes sound devices available locally”. That is interesting. Especially since you can set your XMBC up to be a target for Apple AirPlay sources – making it look like a set of AirPlay speakers to any iDevices on your network. I tested it out with an iPod Touch – and it worked really nicely.
But how to get that option un-greyed-out? The internet suggested the following (might have been nice for paprefs to give me a hint):
sudo apt-get install pulseaudio-module-raop
Now you can try it out:
This will add a new audio device that you can select from your Sound Settings page, with the name of your XMBC. However, if you are like me, you may discover that it it does not work. At all. Except to produce a stream of nasty, choppy, ear-burning noise.
You might even be persistent and try out Pulseaudio-raop2. In which case, if you are like me, you will discover that it, too, does not work, and also crashes quite a lot (which is fair – since it is experimental).
Option 3: Multicast/RTP
I put this in for completeness sake. I didn’t get very far in investigating it as an option. I did a couple of experiments trying to get it to work between two Linux PCs before attempting it with the Raspberry Pi and was getting very choppy sound – so abandoned it and moved on.
Option 4: DLNA/UPnP
My final, and successful(!), attempt involved DLNA/UPnP media streaming. On the paprefsNetwork Server tab was another greyed-outed option “Make local sound devices available as DLNA/UPnp Media Server”.
But how to get it un-greyed-out? The internet suggested the following (might have been nice forpaprefs to give me a hint):
sudo apt-get install rygel
This too adds a new audio device that you can select:
Now go to your XBMC File Manager and look for a new UPnP device to add as a Source:
Unfortunately, you are likely to find nothing there.
Hmm.
Turns out that you have two problems:
- Rygel isn’t running – you need to start it manually from a shell (rygel), or set up init scripts yourself (I didn’t bother);
- Rygel needs to be configured to actually publish PulseAudio’s stream using ‘GstLaunch‘. Obviously.
To configure Rygel, you’ll need to edit one of its configuration files. Rygel can be configuredglobally (/etc/rygel.conf) or per-user ($HOME/.config/rygel.conf). I just edited the global one.
Find the GstLaunch section, and add some config like this* (in my default install it was disabled):
[GstLaunch]
enabled=true
launch-items=mypulseaudiosink
mypulseaudiosink-title=Audio on @HOSTNAME@
mypulseaudiosink-mime=audio/flac
mypulseaudiosink-launch=pulsesrc device=upnp.monitor ! flacenc
* Courtesy of dpc’s blog.
That setup gets Rygel to publish a new stream called ‘GstLaunch/Audio on <my pc>’. The stream will be publishing whatever sound is produced by the PulseAudio ‘upnp.monitor’ source – which is what all of those paprefs settings were actually enabling. It will also transcode that audio stream to FLAC, which is lossless, but also compressed enough to work fine over my WiFi without causing trouble – and with only a couple of seconds of buffering required on the other end.
Now you can add the GstLaunch item as a source through your XMBC File Manager:
Now you are able select your PC’s audio as a stream and connect to it:
Finally, your XBMC is playing your PC’s audio through your sound system. Hooray!