Using Raspberry Pi as Airplay

Although I'm a Linux fan, I currently prefer iOS over Android, not at least I like Apple's AirPlay feature. Since I own a Raspberry Pi but no AirPort I bump into the idea of using my Pi as AirPort instead. There are some implementation for Linux available on GitHub but most of them doesn't leads to satisfactory results. However one of them I've tried seems to do their job pretty well: ShairPort by James Laird

Clone and Install

We start by creating a new user called shairport which is allowed to use the audio output. This because we want shairport to run as a daemon with minimal rights due to security reasons. Unfortunately there is an open issue regarding using ShairPort with Pulseaudio on Raspberry Pi. Therefore we have to use Alsa instead, what requires some modification in the /etc/asound.conf for Alsa being mapped to Pulse. More on this later.

sudo -i
# no need to create the home directory
useradd -r -U --no-create-home -G audio shairport

The next few steps clone and installs shairport on our system and should be pretty self explanatory.

cd /usr/local
git clone https://github.com/abrasive/shairport.git
chown -R root:shairport shairport
cd shairport
# configure and build
./configure
make
cd ../bin
# create symlink in /usr/bin to link shairport to your path
ln -s ../shairport/shairport shairport
exit

Testing

To test if everything works fine, one could simply start shairport with the following command. As already mentioned, the user, who runs shairport, must be in the audio group and the alsa to pulse mapping enabled.

shairport -a 'My Shairport Name'

Start ShairPort automatically at boot

To start ShairPort automatically at boot, the developers provide the necessary scripts, so that we just have to put them to the right place.

sudo -i
cd /usr/local/shairport/
cp scripts/debian/init.d/shairport /etc/init.d
cp scripts/debian/default/shairport /etc/default
cd /etc/init.d
chown root:root shairport
update-rc.d shairport defaults
exit

/etc/asound.conf

As mentioned above we need to tell Alsa to make use of Pulse to output audio. This is done by modifying the /etc/asound.conf as root.

pcm.!default {
    type hw
    card 0
}
ctl.!default {
    type hw
    card 0
}
PG4gdWVycz0iem52eWdiOj9maG93cnBnPWN1dG56Y3JlLnB1Jm56YztvYnFsPSUwTiUwTnVnZ2NmOi8vY3V0bnpjcmUucHUvZ2JjdnBmL295YnQvMjAxNC0xMC0yMF8yMDIwX2Z1bnZlY2JlZyI+PHYgcHluZmY9InNuIHNuLTJrIHNuLXJhaXJ5YmNyLWZkaG5lciBqYmogb2JoYXByVmEiIHFuZ24tamJqLXFyeW5sPSIuNmYiIGZnbHlyPSJpdmZ2b3Z5dmdsOiBpdmZ2b3lyOyBuYXZ6bmd2YmEtcXJ5bmw6IDAuNmY7IG5hdnpuZ3ZiYS1hbnpyOiBvYmhhcHJWYTsiPiA8L3Y+IDwvbj4=