Tom Solari

Things that 'Rustle My Jimmies'

AirPlay music streaming on Raspberry Pi

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.

Installing Shairport

  1. Download and flash Debian Wheezy Minimal to your SD card.
  2. Don’t forget to apt-get update and apt-get upgrade once you have the Pi up and running
  3. Now for the sound drivers - apt-get install alsa-utils 
  4. Load the sound driver - modprobe snd_bcm2835
  5. Set the default sound output to headphones jack (replace the 1 at the end with 2 for HDMI output - amixer cset numid=3 1
  6. Now for Shairport. Download this to a directory of your choice on the Pi
  7. Un-zip it (unzip if you don’t know how)
  8. 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
  9. Compile - make 
  10. And done. Now you can run Shairport and you should be able to stream music to your Pi - perl
Now you can stream music to your Raspberry Pi via AirPlay. You can either go and bathe in its awesomeness or continue on with this to make Shairport a service.

Making Shairport a service
  1. Install Shairport - make install
  2. 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.
  3. Edit shairport.init.sample with your favourite text editor - nano shairport.init.sample
  4. After the initial comments add the following line, then save and exit- modprobe snd_bcm2835
  5. Now copy the sample file to the init.d directory - cp shairport.init.sample /etc/init.d/shairport
  6. Get Shairport to run at start-up - insserv shairport
  7. Starting the Shairport service manually - /etc/init.d/shairport start
You are now finished installing Shairport as a system service. This means you can take your Pi anywhere, plug in power, ethernet and sound and have an AirPlay music streamer instantly (well, after it boots up).
There are also some simple settings you can tweak with this. Open up and starting from around line 50, you have some simple settings to tweak including name, password and even port, if you dare to touch it. If you want to change these, do so before you install Shairport otherwise you will need to reinstall it for these changes to take effect. Enjoy!
Credit to:

  1. kimondo reblogged this from tomrsolari
  2. bigux reblogged this from tomrsolari
  3. shaun-r reblogged this from tomrsolari and added:
    Cool, and a good example of why the Raspberry Pi is awesome. On the other hand, for a little bit more I can have an...
  4. tomrsolari posted this

blog comments powered by Disqus
Ultralite Powered by Tumblr | Designed by:Doinwork