Install Shairport on XBMC Live to get AirPlay audio as well!
May 23, 2011 46 Comments
A couple of weeks ago I showed you guys an easy way to install AirPlayer, which allows you to stream pictures/video from iTuens/iOS Devices.
That’s great isn’t it. It works perfect. But what about the music? Doesn’t Apple’s AirPlay stream music as well?
Well yes it does, sort of. Apple’s new AirPlay goodie still uses the old AirTunes code to stream music.
Recently someone was able to retrieve the private key needed to decode the music.
Today I’ll show you how to install Shairport on XBMC Live to stream your entire music library from your iTunes or iOS Device to your HTPC!
To clarify, this runs perfectly along with AirPlayer. So if you want to stream pictures/videos too,
first follow my earlier guide to install AirPlayer.
Before you start please note ShairPort is still under development and is not working perfectly. Sometimes the audio drops out because of missing frames, specially with iOS devices.
I believe they are working on this. If you have a solution please let me know!
- Go to https://github.com/albertz/shairport and download the zip.
- Unzip it, rename it to albertz-shairport and transfer it (SFTP client) over to your home folder in XBMC
- SSH into XBMC (ssh username@xbmcip)
- sudo apt-get update
- sudo apt-get install libssl-dev libcrypt-openssl-rsa-perl libao2 libao-dev libio-socket-inet6-perl libwww-perl avahi-utils pkg-config
- sudo perl -MCPAN -e ‘install Crypt::OpenSSL::RSA’
- sudo perl -MCPAN -e ‘install HTTP::Message’
- sudo perl -MCPAN -e ‘install IO::Socket::INET6′
- cd albertz-shairport
- make
- perl shairport.pl
- Considering you’re still in the albertz-shairport folder, do: sudo nano shairport.pl
- Find the line (52) where it starts with “my $hairtunes_cli =” change the path to the hairtunes file in the albertz-shairport folder (check picture below for an example).
- sudo cp shairport.init.sample /etc/init.d/shairport
- sudo nano /etc/init.d/shairport
- Find the line (20) where it starts with “DAEMON =” change the path to the shairport.pl file in the albertz-shairport folder (check picture below for an example).
- sudo chmod +x /etc/init.d/shairport
- sudo update-rc.d shairport defaults
- Reboot and test!
This last step will run ShairPort, now you should be able to stream your music to XBMC. I recommend using iTunes until the autor fixes the frame dropping issue with iOS Devices.

Now if you like to start it up automatically every time you boot XBMC continue!




Hi.
Thanks for the great instructions. However I found a few errors that I thought I would let you know about to help others. Also I cant get the restart to work. Works fine when launching manually
Mistakes :-
6,7 and 8 – You cant use the quotes. Otherwise you get an error
Unrecognized character \xE2 in column 1 at -e line 1.
When you run 6 without the quotes you get loads of stuff up about installing perl. Just need to type yes to it. then rerun 6.
Line 13
The default value in this file is
my $hairtunes_cli = $FindBin::Bin . ‘/hairtunes’;
my hairtunes sits in /home/xbmc/albertz-shairport.
Ive tried the following lines in this config and then carried out the rest, but on reboot it just does not start up.
my $hairtunes_cli = $FindBin::Bin . ‘/home/xbmc/albertz-shairport/hairtunes’;
Ive also tried
my $hairtunes_cli = ‘/home/xbmc/albertz-shairport/hairtunes’;
On the 1st line failing I removed it from the rc.d and did all the steps again from 13.
Any ideas on why it isn’t working?
Thanks
Hi,
about the quotes: it’s because you copy paste it, quotes get “damaged” this way…
Try chmod +x on the perl files.
good luck
Op dinsdag 31 mei 2011, om 21:39 heeft
Ah right thanks for the quick reply.
I did this line
sudo chmod +x /etc/init.d/shairport
What other files should I chmod
Try chmodding hairtunes, see if that helps.
Cool. i did chmod +x on all hairtunes and shairport files. Works now
Cheers for your help.
I’m very glad it works
Can you inform me which airtunes clients you use (iTunes/iPhone/…), and do you notice any (how many) dropouts?
No drop outs yet. But ill let you know.
Hi … can you tell me how to do this please?…I’m a bit confused as I’m quite new to the linux CLI. :/
Any ideas how you make shairport publish under the same name each time. Rather than random name?
Ah think I found the line
Please share
Line
$apname = “ShairPort $$ on ” . `hostname`;
Change to whatever you want.
$apname = “XBMC Name”;
Sorry its in shairport.pl and full line is
my $apname = “ShairPort $$ on ” . `hostname`;
I changed mine to
my $apname = “MediaCenter”;
Hi, as far as I can tell I’ve gone through the whole process successfully,
however on the last line : “perl shairport.pl” I get the following error:
“Perl v5.10.0 required–this is only v5.8.8, stopped at shairport.pl line 29.
BEGIN failed–compilation aborted at shairport.pl line 29.”
It seems I need to upgrade Perl somehow. Any ideas how? or any insights into this problem?
Thanks
Try sudo apt-get update & sudu apt-get upgrade
Verstuurd vanaf mijn iPhone
you could try
sudo apt-get update
sudo apt-get upgrade
Thanks both of you guys for your quick responses. tried the update and upgrade. but, no dice jim rice!
I’m running minimal ubuntu on AppleTV, any known issues with that?
No known issues, give it a shot
Verstuurd vanaf mijn iPhone
Thanks Tripkip, but nothing I do allows me to upgrade Perl!?!?
Follow this: http://trinitum.org/wp/upgrading-perl-on-ubuntu
If I have xbmc running on windows XP, how do I get Shariport installed? Also, will it be tied to XBMC or will it run regardless?
If you want this to run on winxp you re on your own.
Hint: download python for windows
Good luck
Verstuurd vanaf mijn iPhone
I was able to install Shairport OK and even execute: perl shairport.pl with everything working.
My problems start with trying to configure Shairport to start up automatically.
Is there anyone having similar issues?
Are there any suggestions on what I should try or maybe what information I can supply to more easily diagnose the issue?
G
@GTRAIN: i have similar issues with automatic start. I configured my /etc/init.d/shairport as needed and it even is executed on startup but if i try to “airplay” something i can’t hear anything. at the moment i think it’s because shairtunes is started by root on startup. If i kill the autostarted shairtunes and run it again with my user(xbmc) everything works perfect. any ideas !?
Yeah, it’s definitely because it’s starting as root. You need to edit your /etc/init.d/shairport and after the pidfile= line add:
USER=username
GROUP=groupname
then scroll down to the start case and enter:
start() {
echo -n “Starting shairport: ”
start-stop-daemon –start -c $USER:$GROUP \
–quiet –pidfile “$PIDFILE” \
–exec “$DAEMON” -b –oknodo — $DAEMON_ARGS
log_end_msg $?
}
instead of what’s already there. Be careful cutting and pasting from wordpress blogs as they always do something funky to quotes. If in doubt, cut and paste the above and then manually delete and re-type all the quotation marks to be sure. As long as you put the right username and group in the first bit, then this will launch the service as your user and it’ll work automatically – well, at least it did for me!
Jim
Lol! Also the things that look like long minus signs above are actually two minus signs. F@£%ing wordpress! To be clear start, quiet, pidfile, exec, oknodo and $DAEMON_ARGS (this last one has a space in front of it) all have a double minus sign in front of them. start-stop-daemon -c and -b are all singles….. I’m off for a bit of rest in a dark room now…..
Hello,
Thank you for this post, very useful. It works like a charm in addition with the Airplay script
I confirm, don’t copy/paste 6, 7 and 8 commands, write it.
Also, it seems point 13 is useless in my case, the default value works fine.
When I changed with the absolute path it has stopped to work and I faced the following error message when running “perl shairport.pl”:
“Can’t find the ‘hairtunes’ decoder binary, you need to build this before using Shairport.”
Greg.
Hi again,
I followed your shairport guide and now I face a problem. When I stream a song via shairport I can’t have the sound anymore if I wan’t to stream a youtube video (for example) via Airplay. I see the following error message on my TV:
failed to initialize audio device
check your audiosettings
It seems like shairport doesn’t release the audio device…
Did someone experienced the same behavior?
Thanks for any help you can bring to me
Greg.
In WordPress you can use code tags so it keeps it intact.
Hello
I have installed this and it has run perfectly. I have the device showing on my devices ipad, iphone, itunes, and when i try to play anything I get this message:
ALSA snd_pcm_open error: No such file or directory
FATAL: Could not open ao device
ALSA snd_pcm_open error: No such file or directory
FATAL: Could not open ao device
Can anyone please help?
Thanks
Phill
same here
for all that facing the problem that xbmc blocks the sink (alsa) … or even don’t have alsa installed …
if you’ve installed pulse audio just switch in the xbmc audio settings to pulse audio
and change the default driver in
/etc/liboa.confto pulse.you could try it manually before changing the conf …
perl /home/xbmc/albertz-shairport/shairport.pl --ao_driver=pulse --server_port=5008 --apname=PulseAudio_TEST
….
Installs ok, starts ok, ipad and itunes connects ok and the seconds start counting in music players, but no sound. : /
What could be wrong? For the record the other guide with Airplay worked just fine (sound and video).
I still can’t get this to start automatically when XBMC boots. If I SSH to XBMC Live and run “perl shairport.pl” all is good.
Could somebody tell me what I have missed?
If you don’t have the skills to get this working … wait for XBMC Eden.
First see what Jim has to say…
In the shairport in INIT.D I changed:
PIDFILE=/var/run/$NAME.pid
to
PIDFILE=”/var/run/$NAME.pid”
and later on:
start() {
echo -n “Starting shairport: ”
start-stop-daemon –start –quiet –pidfile “$PIDFILE” \
–exec “$DAEMON” -b –oknodo — $DAEMON_ARGS
to
start() {
echo -n “Starting shairport: ”
start-stop-daemon –start -c $USER:$GROUP \
–quiet –pidfile $PIDFILE \
–exec $DAEMON -b –oknodo — $DAEMON_ARGS
I would also mention that this (airplay and airtunes) are now integrated fully into xbmc pre-eden, so if you’re brave enough to take the plunge…. if you build from source you have to make libshairport from the xbmc src first manually if you’re on linux because its not included in the makefile. Jim
It’s working on my HTPC now.. And i got no skills for setting this up
After i execute the command “perl shairport.pl” the device is vissible on my network and sound is working fine.
But when i close the terminal window, the shareport device is shut down? – It should be running all the time in XBMC Live? Further more start automatically everytime the computer starts!?
Hi!
I have just triedt to install shairport, but i have some issues:
When running this:
sudo apt-get install libssl-dev libcrypt-openssl-rsa-perl libao2 libao-dev libio-socket-inet6-perl libwww-perl avahi-utils pkg-config
i get that error:
Package libao2 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
libao-common
E: Package ‘libao2′ has no installation candidate
and later this one:
xbmc@XBMCLive:~/albertz-shairport$ make
make: pkg-config: Command not found
make: pkg-config: Command not found
cc -O2 -Wall -DHAIRTUNES_STANDALONE hairtunes.c alac.c -o hairtunes -lm -lpthread
hairtunes.c:37: fatal error: openssl/aes.h: No such file or directory
compilation terminated.
make: *** [hairtunes] Error 1
I am a little lost, i had this running, but i decided to reinstall xbmc-live for some reasons. now its not working ;(
Hope you can help.
THX
Got this working! Delighted.
However, it’s awfully quiet, relative to using local sources. Have turned up everything on my Mac – successfully transmitting via iTunes and AirFoil. Any tips?
Got it working – it appears in my list of options in iTunes – and it streams music.
But it doesn’t appear in the “Multiple Speakers…” dialogue. Is this normal?
I have this working on my XBMC live instance, but audio is only output via the analogue out and not via the HDMI interface.
When I have Airplayer running, audio for YouTube playbacks works just fine over HDMI so I am a bit confused at the moment.
Anyone have any ideas? My libao.conf is configured for alsa.
You need to set the device for also in the libao.conf file as well
Below are examples where you can use front, iec958, default, etc. turn on debug to see what it is using…
default_driver=alsa
#dev=front
#dev=iec958
#dev=dmixer
dev=default
debug
Help Me!!!
I Cannot copy shairport,init.sample to /etc/init.d/shairport
cp: cannot create regular file `/ect/init.d/shairport’: No such file or directory
Pingback: AirPlay no Xbmc « Uelei.TK
Pingback: AirPlay no Xbmc « uelei