Introduction: AirPlay Speakers

I had an old Rasapberry pi model B and nothing to do with it since I have a different model, so I decided to turn it into a really simple AirPlay server that starts automatically when you plug it in. It is very cheap and convenient. It's very easy but it takes a while for some of the installations.

Step 1: Materials

You will need...
-Raspberry pi running raspbian
-power supply
-wifi adapter
-some speakers(or you can have it play through HDMI if you want)

EXTRA:
-LED
-a couple female to female leads

Step 2: Installing the Software

You need your wifi adapter in and connected to the wifi (there are lots of tutorials online if you don't know how to do this). This step is from Jordan Burgess's AirPlay tutorial:
http://jordanburgess.com/post/38986434391/raspberry-pi-airplay

First, upgrade your packages by entering the following commands into LX Terminal:
sudo apt-get install update
sudo apt-get install upgrade

Next, you can set the audio output to whichever port you want. For this tutorial, we will set it to the headphone port:
sudo amixer cset numid=3 1

Now you need to get shairport. Enter the following command, (yes it is very long and it will take a while to finish so you might as well go do something else while you wait):

sudo apt-get install git libao-dev libssl-dev libcrypt-openssl-rsa-perl libio-socket-inet6-perl libwww-perl avahi-utils libmodule-build-perl

Now you have to install Perl Net-SDP:

git clone https://github.com/njh/perl-net-sdp.git perl-net-sdp
cd perl-net-sdp
perl Build.PL
sudo ./Build
sudo ./Build test
sudo ./Build install
cd ..

Now setup Shairport:

git clone https://github.com/hendrikw82/shairport.git
cd shairport
make

Step 3: Running Airplay

You can now run AirPlay from any LX Terminal session

If you aren't already, go to the shairport directory by entering
cd shaiport

Now run it by entering

./shairport.pl -a (server name)

If you are connected to wifi, it should say something like "Established under name....."

Now, go on whatever iOS device you want, pull up AirPlay, and connect. You can now stream music wirelessly to you speakers.

Step 4: Running AirPlay at Boot

First what you have to do is make your pi login automatically at boot. Enter the following command:

sudo nano /etc/inittab

This will open a text file. Now find the line that starts with '1:2345...'
Comment it out by putting a # in front of it. Now, below it, add the line

1:2345:respawn:/bin/login -f pi tty1 /dev/tty1 2>&1

Close it with CONTROL+X, Y, ENTER

Your pi should now no longer require a username or password.

Next we have to add an AirPlay File. Enter the following command:

sudo nano AirPlay

This will pull up a blank text editor. Enter your AirPlay commands:

cd shairport
./shairport.pl -a (server name)

Now close it by doing control+X, then Y, then ENTER
Next, make that file executable. Enter:

sudo chmod +x AirPlay

Now open .bashrc by entering

sudo nano .bashrc

And add the line

./AirPlay

Now close it by doing CONTROL+X, Y, ENTER

Now your pi should automatically start an AirPlay server when you plug it in. It will take a while to get it started, it's still running a normal boot, but now, when ever you log in, which it does automatically now, it starts an AirPlay server. All you need to do is plug it in with the wifi adapter and some speakers and you have a working AirPlay server. Enjoy!

Step 5: Extra: Notification LED

I decided to add a little LED Bulb that would go on about when the AirPlay Server goes up. There is a slight delay between when the bulb goes on and when the server goes up by about 5 seconds, but it is still kinda cool.

Take LED and connect one side to GPIO18 and the other to a Ground. To do this, You can use some Female to Female leads and connect directly to the LED. I only had male to males, but I found that if I took pliers, I could pull out the metal tip, leaving a female header that worked perfectly. It's a very tight fit though and you have to be careful not to Bend the pins, but it works really well.

Now you have to create a python script that will activate the pins. Open a new script and add the following lines of code:

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
GPIO.output(18,True)

Now save the file as LEDON.py
Next reopen the AirPlay nano editor with the command

sudo nano AirPlay

And add the following at the top, before 'cd shairport'

sudo Python LEDON.py

Next, save and exit. Now if you reboot, the LED will go on a few seconds before the AirPlay server goes up.

NOTE:
The LED doesn't turn off on its own. I did this by creating a new Python script named LEDOFF.py with the following commands:

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(18,GPIO.OUT)
GPIO.output(18, False)

Then I added it to the end off .bashrc by entering:

sudo nano .bashrc

Then adding -- sudo python LEDOFF.py -- Below the './AirPlay'

Now when the server is running, if you cancel it by doing CONTROL+C, it will stop the server and turn off the LED

Comments

author
kmicb5 (author)2017-03-28

I realize this is an old thread, but what the hell, I got this to work, but the volume is REALLY low....ideas? (yes, everything is turned up to max but still quiet)

author
TheChick3n (author)2015-09-12

It actually shows up in System Preferences, but says "The selected device has no output controls"

author
Slapshot135 (author)2015-05-13

I'm not sure, I've always had a few seconds of delay, so it's probably just the pi, you've probably learned by now that it's not the fastest computer...

author
Slapshot135 (author)2015-05-10

If you mean between the device that You've connected to the pi, then yes. It's normal, just slow internet. The music is getting streamed through your internet so the slower your internet the bigger the delay.

author
cyanide4c (author)Slapshot1352015-05-13

My lan is pretty fast, and no other devices have this issue, wired or wireless, just the py and py2, could it be the code itself that creates a little delay?

author
cyanide4c (author)2015-05-09

Hi, nice tutorial, I always have a sound delay between my other devices and a rasp pi (multiroom setup), do you have experience with that issue?