Ever since I got my Raspberry Pi(s), I’ve been looking for something for them to do. AirPlay was an answer to that, but as I found out, it is a little harder to get music streaming over AirPlay to a Raspberry Pi than videos or photos. Who would have thought!
Everybody knows XBMC don’t they? If not, you should, as it is one of the bigger open source media centers out there. And it supports AirPlay! And someone has ported XBMC to the Pi. Yes! Raspbmc is the name of this XBMC Pi port so I went ahead and downloaded and flashed the image so an SD card. I then found out that XBMC doesn’t actually receive streamed audio over AirPlay due to “broken code”. What?! Music was one of the main reasons I want to set up AirPlay in my house. Sigh.
After searching some more, I found Shairport, basically just a bunch of Perl scripts. I also stumbled across a Minimal Debian Wheezy image for the Pi which contains updated audio drivers. Things are starting to look up. So I downloaded it all, copied, flashed, installed, updated and ran Shairport and a bit of troubleshooting later, I had a music-streaming-capable AirPlay client! So here is how I did it.
- Download and flash Debian Wheezy Minimal to your SD card.
- Don’t forget to apt-get update and apt-get upgrade once you have the Pi up and running
- Now for the sound drivers - apt-get install alsa-utils
- Load the sound driver - modprobe snd_bcm2835
- Set the default sound output to headphones jack (replace the 1 at the end with 2 for HDMI output - amixer cset numid=3 1
- Now for Shairport. Download this to a directory of your choice on the Pi
- Un-zip it (unzip file.zip if you don’t know how)
- Download the dependencies for Shairport - apt-get install build-essential libssl-dev libcrypt-openssl-rsa-perl libao-dev libio-socket-inet6-perl libwww-perl avahi-utils pkg-config
- Compile - make
- And done. Now you can run Shairport and you should be able to stream music to your Pi - perl shairport.pl
Making Shairport a service
- Install Shairport - make install
- The sound driver needs to be loaded upon reboot for audio output to work so we need to cater for this, otherwise AirPlay will cease to work.
- Edit shairport.init.sample with your favourite text editor - nano shairport.init.sample
- After the initial comments add the following line, then save and exit- modprobe snd_bcm2835
- Now copy the sample file to the init.d directory - cp shairport.init.sample /etc/init.d/shairport
- Get Shairport to run at start-up - insserv shairport
- Starting the Shairport service manually - /etc/init.d/shairport start