Install Shairport on XBMC Live to get AirPlay audio as well!

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!

  1. Go to https://github.com/albertz/shairport and download the zip.
  2. Unzip it, rename it to albertz-shairport and transfer it (SFTP client) over to your home folder in XBMC
  3. SSH into XBMC (ssh username@xbmcip)
  4. sudo apt-get update
  5. sudo apt-get install libssl-dev libcrypt-openssl-rsa-perl libao2 libao-dev libio-socket-inet6-perl libwww-perl avahi-utils pkg-config
  6. sudo perl -MCPAN -e ‘install Crypt::OpenSSL::RSA’
  7. sudo perl -MCPAN -e ‘install HTTP::Message’
  8. sudo perl -MCPAN -e ‘install IO::Socket::INET6′
  9. cd albertz-shairport
  10. make
  11. perl shairport.pl
  12. 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!

  13. Considering you’re still in the albertz-shairport folder, do: sudo nano shairport.pl
  14. 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).
  15. sudo cp shairport.init.sample /etc/init.d/shairport
  16. sudo nano /etc/init.d/shairport
  17. 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).
  18. sudo chmod +x /etc/init.d/shairport
  19. sudo update-rc.d shairport defaults
  20. Reboot and test!
Advertisement

46 Responses to Install Shairport on XBMC Live to get AirPlay audio as well!

  1. Dale says:

    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

    • tripkip says:

      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

  2. Dale says:

    Ah right thanks for the quick reply.

    I did this line

    sudo chmod +x /etc/init.d/shairport

    What other files should I chmod

  3. Dale says:

    Cool. i did chmod +x on all hairtunes and shairport files. Works now

    Cheers for your help.

  4. Dale says:

    Any ideas how you make shairport publish under the same name each time. Rather than random name?

  5. Dale says:

    Line

    $apname = “ShairPort $$ on ” . `hostname`;

    Change to whatever you want.

    $apname = “XBMC Name”;

    • Dale says:

      Sorry its in shairport.pl and full line is

      my $apname = “ShairPort $$ on ” . `hostname`;

      I changed mine to

      my $apname = “MediaCenter”;

  6. Trck says:

    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

  7. Chris says:

    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?

  8. GTRAIN says:

    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

  9. Sebastian says:

    @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 !?

    • Jim says:

      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

      • Jim says:

        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…..

  10. Greg says:

    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.

  11. Greg says:

    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.

  12. Dale says:

    In WordPress you can use code tags so it keeps it intact.

     like this 
  13. 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

  14. joesol says:

    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.conf to 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

    ….

  15. Peter says:

    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).

  16. Roy says:

    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?

    • tripkip says:

      If you don’t have the skills to get this working … wait for XBMC Eden.

    • Commander Keen says:

      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

      • Jim says:

        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

  17. Rasmus says:

    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!?

  18. paul says:

    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

  19. Josh R says:

    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?

  20. Nick says:

    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?

  21. Mark says:

    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

  22. martin says:

    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

  23. Pingback: AirPlay no Xbmc « Uelei.TK

  24. Pingback: AirPlay no Xbmc « uelei

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 103 other followers