How to set up a Raspberry Pi AirPlay receiver

How to set up a Raspberry Pi AirPlay receiver

Apple’s AirPlay is an incredibly useful feature – assuming, of course, that you have enough Apple products to make it work. As you probably know, AirPlay allows you to sling from an Apple device to another device. But while Apple has been a little nicer than usual about licensing the tech out to third-party companies, there’s still a good chance that your particular stereo isn’t AirPlay-capable. That’s too bad, but its’ a problem you can solve with – you guessed it – a Raspberry Pi. You can actually make a Raspberry Pi AirPlay receiver with nothing more than a few commands in Terminal. Plug that Raspberry Pi into your TV with an HDMI cable, and bingo: you’re ready to rock, and all without having to buy an Apple TV. The only catch is that this receiver is audio-only. Ready to check it out? Here’s how to set up a Raspberry Pi AirPlay receiver.

How to set up a Raspberry Pi AirPlay receiver

You don’t need any special equipment for this project – all we’re going to do is build and install an AirPlay audio player called Shairport Sync. We’re going to start with Raspbian installed (if you haven’t done this yet, check out our piece on how to install Raspbian on the Raspberry Pi).

Step 1: Check for updates

Assuming you’ve already got Raspbian installed, let’s just get on the same page here by making sure everything is up-to-date.

Open Terminal and run the following commands:

sudo apt-get update
sudo apt-get upgrade

Great, good as new. Moving on!

Step 2: Install the necessary packages

We need a few packages to make this work. Let’s get them!

sudo apt-get install autoconf automake avahi-daemon build-essential git libasound2-dev libavahi-client-dev libconfig-dev libdaemon-dev libpopt-dev libssl-dev libtool xmltoman

Okay, so maybe that’s more than “a few.” All of those things after “install” are individual packages that our Shairport Sync build will rely on. Some are libraries, which will allow Shairport Sync to perform different tasks. Others are tools that will be used in our build process down in Step 4.

Step 3: Clone the Shairport Sync repository

As mentioned earlier, Shairport Sync is the star of this show. So, naturally, we’ll need the Shairport Sync repository. It’s over on GitHub, but we want it on our Raspberry Pi, so let’s clone it – or, in other words, let’s make a local copy of the repository on the Raspberry Pi. To do this, we’ll just use a line in Terminal:

git clone https://github.com/mikebrady/shairport-sync.git

Step 4: Build and install Shairport Sync

Now we have our own version of the Shairport Sync repository on our Pi, but we still need to build and install it. But before we can do that, we need to be in the right directory:

cd shairport-sync

Now it’s time to get building. Enter these two commands in Terminal:

autoreconf -i -f
./configure --with-alsa --with-avahi --with-ssl=openssl --with-systemd --with-metadata

Why all the dashes and “with” things? They tell us what our Shairport Sync build will support. Our new build supports Advanced Linux Sound Architecture (ALSA) (–with-alsa). It also supports Avahi, a system-wide zero-configuration (zeroconf) networking service (–with-avahi) and OpenSSL encryption (–with-ssl).

On top of that, we’ve added support for Shairport Sync to be launched automatically on boot (–with-systemd) and gave Shairport Sync the power to pipe metadata to compatible applications (–with-metadata).

These particular options aren’t the only ones you can tack onto your build. For more about all the different things your Shairport Sync build could support, check out the Shairport Sync GitHub page.

With the build system prepared, we can move to compiling and installing Shairport Sync. Fortunately, this is requires a much quicker couple lines of code:

make
sudo make install

Now we have Shairport Sync!

Step 5: Enable Shairport Sync to start on boot

We’re almost set here – just one last step. Shairport Sync will make your Raspberry Pi an AirPlay receiver, but it won’t be very convenient if you have to start Shairport Sync on your Raspberry Pi before you can use the feature. So let’s just have Shairport Sync start up automatically when you Pi boots up.

We added support for this feature in our build (–with-systemd, remember?), but we still have to turn the feature on. To enable Shairport Sync to start automatically on boot, run the following command:

sudo systemctl enable shairport-sync

Your Raspberry Pi will now be AirPlay-ready from the moment it boots. But you don’t have to reboot to get Shairport Sync running right now (though that would work) – you can just use another Terminal command:

sudo service shairport-sync start

That’s it! Your Raspberry Pi AirPlay receiver should be all set. To confirm that it works, hop on an Apple device and head to the AirPlay menu or to System Preferences>Sound. Your Raspberry Pi should be on the list, ready to receive AirPlay casts!

20 Comments on "How to set up a Raspberry Pi AirPlay receiver"

  1. So, it’s on the list and the iPad is happy to share. Nothing happens on screen though. What have I missed?

  2. Hariprasad Valath | September 18, 2017 at 5:18 am | Reply

    This didn’t work for me. Pi was not listed in AirPlay Devices of iPhone 6 running iOS 10. Anybody has succeeded? Please share.

  3. Worked first time. Just followed the instructions. Thanks for this fantastic tutorial.

    I am using the Raspberry Pi 3 with a digital audio HAT board.

    The device comes up as an Airplay device on my iPhone 6 (iOS 11.0.3) about thirty seconds after powering up the Raspberry Pi.

  4. My Pi is on the AirPlay list but I am having trouble connecting it. Whenever I try to select Pi on my list it says “Unable to connect to Pi.” Anyone know how to fix this?

  5. Andrew Walters | November 8, 2017 at 6:13 am | Reply

    Will this run along side MPD?

    I’ve already used this same hardware with MPD, which lets remote clients play songs from the music library on the Pi’s SD card. This would give iOS devices another way to use the speakers.

    MPD does use ALSA. It also has the advantage that I can get clients for Kindles and other Android devices.

    Alternately, can Kindle or Android use AirPlay speakers?

    Thanks.

  6. Jeffrey Findley | November 12, 2017 at 7:22 pm | Reply

    Unfortunately, I’m not getting any sound output from my USB sound card when I connect via AirPlay. Speaker test works: speaker-test -Dhw:1,0 -c2 -twav

    Any suggestions? Thanks!

  7. Can confirm this worked for me! Using iPhone 6 with iOS 11.0.3. Thank you!

  8. Really great description! Works!

    Thanks.

  9. Thanks. How can I change the name of the AirPlay receiver?

  10. Thank you! This is much more helpful than the GitHub page. Works with Raspbian Stretch with a hifiberry-amp. I’ve got some issues with the bottom of the volume slider being silent but I anticipate this being fixed by adjusting the volume range in /usr/local/etc/shairport-sync.conf (don’t know why it put this is the BSD location).

  11. Edward Hill-Palmer | January 12, 2018 at 1:57 pm | Reply

    This works well over Wi-Fi, but i am installing the Pi in my car. Does anyone know if you can get the audio working via Bluetooth? i can connect the Pi to my iPhone 7, and the iPhone thinks audio is playing, but nothing coming through on the Pi3? Thanks!

    • You have to change the Raspberry Pi to output audio through the audio jack.

      Type this into the command line:

      amixer cset numid=3 1
      sudo reboot

      And it should work after that.

  12. Gerhard Bruendel | March 12, 2018 at 1:48 am | Reply

    This is a great description, I worked through it, but when I started the service manually with:

    sudo service shairport-sync start

    This message appears:
    Failed to start shairport-sync.service: Unit shairport-sync.service is masked.

    I am not very familiar with RPI and the Debian Linux.

    Thanks!

  13. Hello,

    I’m getting a segmentation fault « aclocal: /usr/bin/autom4te failed with exit status : 139 » after running « autoreconf -i -f » on my Raspberry Type B with Raspbian freshly upgraded.

    Any thoughts on that?

    Thanks!

  14. When I plug the Raspberry Pi into the speaker it plays, but its very quiet and it lags and doesn’t play some of the song.

  15. Gerhard Bruendel,

    When a service is masked, you cannot change the running status of it. You should unmask it, and re-try to start it. Start means the service will start running, enable means upon different run levels (shutdown, reboot etc..), this service will run.

    So, you should start the service and test if its working. Once you are certain you want it working at boot, reboot, do enable command.
    FYI, on Debian, shairport-sync can be installed over apt-get, and it works fine with iOS11.3/iPhone8

  16. Super ça marche nickel !!! 🙂

Leave a comment

Your email address will not be published.


*