Turn A Raspberry Pi Into An AirPlay Receiver For Streaming Music

Few things are better than kicking back on the couch and streaming your favourite album wirelessly to your stereo from your phone. That's easy to do with AirPlay, but if you don't want to pay for Apple's solutions, a Raspberry Pi does the job remarkably well.

An HDMI or composite video cable: You'll need this cable to connect your Raspberry Pi to your television or monitor temporarily to get the Raspberry Pi set up.

An 8GB Class 10 SD card (or better) and a card reader (if you don't have one built into your computer): You can go smaller or slower, but an 8GB Class 10 card will get you the best performance, and they're pretty cheap. Most SD cards will work, but some aren't compatible and will therefore cause issues. You can find out which cards are compatible, or locate a place to buy a compatible card with an operating system pre-installed, on this page.

A USB keyboard and mouse: Any standard USB keyboard or mouse will do. You'll only need these for the setup process, so whatever you have attached to your computer right now should do the trick.

A good quality, micro USB power supply that can provide at least 700mA at 5V: Most modern smartphone chargers supply 700mA at 5V, but not all do. Check the bottom of your charger and look for a block of text. You'll see its output values in that text which may read 0.7A instead of 700mA). If it offers at least that much power, you're good to go. Don't use a poor quality charger or you may run into problems.

A 3.5mm stereo audio cable : You need this to run the Raspberry Pi into your stereo.

An iOS device or computer: You'll need an iPhone, iPod Touch or iPad, or a computer with iTunes installed as a source for your music. Theoretically an Android device with software like doubleTwist would also work, but we haven't tested it.

What You Will (And Won't) Get

The Raspberry Pi makes a fantastic AirPlay device. When you've set it up, you'll have a small box connected to your stereo that functions in a similar fashion to AirPlay-enabled speakers. When it's plugged in and booted up it will automatically load everything necessary to start AirPlay with no need for an external monitor or keyboard. It lets you stream music to any speakers you own for less than half the price of an AirPort Express, and you can still use it for any other Raspberry Pi project you want to take on. That's a serious win-win. The one downside? The Raspberry Pi doesn't currently support AirPlay Mirroring to send video content.

To make the AirPlay receiver start automatically without the need for a keyboard or monitor, we need to set Raspbian to log you in automatically. During the setup process at the Raspi-config screen, change the "Start Desktop on Boot?" setting to yes. If you're already up and running, type this command into the terminal to load up Raspi-config again:

sudo raspi-config

Finally, the AirPlay functionality may require a few packages not initially included in your installation, so you'll want to update your packages before you get started. Type these commands into the console:

sudo apt-get update
sudo apt-get upgrade

The update might take a little while, so grab a beverage and sit back. Once you're booted up into Raspbian and everything is working properly, we can start setting up the AirPlay function.

Note: It's possible to install everything you need using console commands, but we'll use the slightly easier Raspbian interface so that you can continue to use your Raspberry Pi for other roles as well.

Set Up Your USB Wi-Fi Adaptor

First off, we need to get the USB Wi-Fi adaptor working. This is very simple with Raspbian installed:

Connect your USB Wi-Fi adaptor to the Pi if it isn't already.

Open the WiFi Config application on the desktop.

Select your adaptor from the drop down list.

Sign into your home network.

That's it for the Wi-Fi adaptor. If you like, open up the Midori browser from the desktop to make sure the internet is working. Raspbian will remember your selection, so even if you disconnect the Wi-Fi adaptor at any time during the process it will automatically load up again when it is connected to the Pi.

Next up we need to get the sound card up and working. First, connect your USB sound card into the Raspberry Pi, and hook it up to your stereo with the 3.5mm audio cable (or plug in headphones). Next, we're going to use a terminal command to select it. Open up LXTerminal from your desktop and type in the following command:

aplay -l

Your USB card should display as something like, "card 1: set [device name], device 0: USB Audio." That means it has been recognised by the Raspberry Pi. Now we need to test the sound. Type:

Alsamixer

This loads up the software to test the audio output. Press F6 to change the output type and select your sound card. Now we need to test the output:

speaker-test

You should hear a tone from your speakers verifying that the USB sound card is working.

Finally, Raspbian doesn't automatically load the USB sound card when it boots. This means we have to edit the configuration file. Type the following:

cd /etc/modprobe.d
sudo nano alsa-base.conf

This opens the alsa-base.conf file. Scroll down towards the end of the file and look for this line:

options snd-usb-audio index=-2

Comment that line out with a "#" symbol at the start of the line. Hit Ctrl+X to save and exit.

Now your sound card and Wi-Fi adaptors will both work automatically every time you start the Pi.

Install The Shairport AirPlay Emulator

Shairport is the software that actually makes AirPlay work, and it takes a little while to set up. It's not a difficult process, but you will need to give yourself about 30 minutes because it requires a lot of downloading and installing of software.

We need to install a few items before we can get Shairport. Type this into the console:

This command starts Shairport with your Raspberry Pi named "AirPi" (you can change it to whatever you want). Grab your iOS device, pick the music app of your choice, and tap the AirPlay button. You should see "AirPi" listed as an output device. Tap that, and the music should start streaming from your USB sound card within a couple of seconds.

We're not quite done yet. Shairport doesn't automatically load when you start your Raspberry Pi, and since we want to make our AirPlay device work without any peripherals we need to perform one more step. From your home directory, type:

This loads up the Shairport file we need to edit. Look through the file for the "DAEMON_ARGS" line, and change it so it looks like this:

DAEMON_ARGS="-w $PIDFILE -a AirPi"

Save the file (Ctrl+X), and you're all set. Shairport should launch on startup every time. You can now move the Raspberry Pi anywhere you like and do whatever else you want with it. As long as the USB sound card and Wi-Fi adaptor are plugged in, they will load up when you turn the Raspberry Pi along with Shairport. That means you don't need a monitor, keyboard or mouse next to your stereo for it to work.

Once you're set up, all you need to do to use the AirPlay function is plug the Raspberry Pi in, and wait for it to boot up. Once the operating system loads (it usually takes about 30-40 seconds), you can instantly and easily send all your music through the Raspberry Pi.

Take It Further

The basic AirPlay functionality is just the tip of the iceberg. You can do a lot more with it once the functionality is set up. Here are a few different ideas that expand the AirPlay functionality in the Raspberry Pi way past the AirPort Express:

Only logged in users may vote for comments!

Get Permalink

Trending Stories Right Now

Spring is nearly upon us, which means the return of the dreaded Magpie season. Those ruthless swooping demons are extremely aggressive during this time of year as they defend their nests with gusto around gardens, schoolyards and parks. So is it legal to kill one of these angry birds before it pecks an eye out?

The KFC Zinger Double Down King is an "all meat" burger comprising cheese, bacon and a beef patty sandwiched between two KFC breast fillets. In other words, it takes the OTT concept of the KFC Double and elevates it to ludicrous proportions.
Tragically, the Double Down King isn't available in Australia, but don't let that stop you from sampling its colon-clogging delights - as the following taste test demonstrates, it's possible to build your own. The results are spectacular... and probably a bit lethal.