HowTo: Raspberry Pi – Install “Shairport” Airplay on the Raspberry Pi

Anyone who uses one (or more) Apple devices certainly knows the AirPlay function. Thanks to this, all types of media can be streamed to other devices in the network. You can display photos on an AirPlay-enabled television, play videos or play music on AirPlay-enabled speakers.

At least you can easily achieve the latter with a RaspberryPi and convert a RaspberryPi into an AirPlay-capable speaker.

I use this solution in my MagicMirror for example. So you can also use the RaspberryPi (which is built into the magicMirror) as a music speaker. 🙂

Everything you need to set up your RaspberryPi is described in the following article.


Safety instructions

I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
https://www.nerdiy.de/sicherheitshinweise/

Affiliate links/advertising links

The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other useful projects in the future. 🙂 


Requirements

Helpful articles:
Before you start with this article you should have prepared the RaspberryPi so that it is accessible via the network and controllable via SSH.

The following three articles describe what needs to be done to prepare the RaspberryPi:
RaspberryPi – setup for nerdiys!
RaspberryPi – The first configuration!
RaspberryPi – Control the RaspberryPi via SSH

Required tool:
-no-

Required material:

In the following list you will find all the parts you need to implement this article.


Log in to the RaspberryPi via SSH

To start, you must first log in to the Rasp Pi with Putty via SSH. How to do this is in the article RaspberryPi - Control the RaspberryPi via SSH described.

After entering your username and password you can enter the first commands.

Update package management

The package management in Linux is a "central place" through which various software packages can be installed. In order for this to work reliably, the lists and sources of the package management should be updated before each installation of new packages.

To start the update of the package management you have to enter the following command.
sudo apt-get update && sudo apt-get upgrade
Depending on how long ago your last update of the package management was, this process can now take a while. The lists that refer to the individual package sources are updated first.
After that, the packages themselves are updated. Since additional memory is occupied, you will be asked again for your consent. You have to confirm this with a "J" and "Enter".
Once the update is complete, you will see a small summary of the duration and scope of the update.

Install Chairport

Installing Shairport is very easy thanks to the package manager.

Simply enter the following command in the console of your RaspberryPi.

sudo apt-get install shairport-sync

You can confirm any request that this will take up memory by pressing “Y” and “Enter”.

The installation then runs automatically.

To start Shairport after installation, you must now execute the following command

sudo systemctl start shairport-sync


Show status

Thanks to the command line tool systemctl, you can easily get an overview of the status of your Shairport server.

To do this, simply enter the following command into the console of your Raspberry Pi.

sudo systemctl status shairport-sync

Here you can now see whether the Shairport server is “active” or “inactive”.


Activate autostart

So that your Shairport server starts automatically again after restarting the Raspberry Pi, you should now activate its autostart.

Simply enter the following command in the console of your RaspberryPi.

sudo systemctl enable shairport-sync


Start music playback

That's all it was. You should now be able to use your self-made AirPlay receiver on your iPhone (or other Apple device). 🙂

For example, you will now find the marked symbol in your “Podcasts” app.

As soon as you click on it...

...a menu should open in which the AirPlay speaker you have just set up (here called “MagicMirror”) is displayed.

As soon as you click on it, the music should start playing.


Have fun with the project

I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂

PS Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂

Buy Me a Coffee at ko-fi.com       

12 comments

  1. Hello, my name is Achim Graf
    I have the problem that Shairport-sync, whether on the Rapi 3b+ or 4b, does not connect to Airmusic on a rooted Amazon tablet. Airmusic on the tablet immediately finds the Raspi with the Shairport sync started, but when I want to connect it, the Airmusic icon turns blue for 1 second, then red for 3-5 seconds and the game starts over. After about 5 runs, an error message comes up with tips that I have already gone through several times.
    Raspian was reinstalled each time with Raspberry Pi Imager, everything as described.
    Airmusic connects immediately to Shaiport4w on the notebook and to my Sony Android TV.
    I'm getting desperate, it would be great if you could help me get this going.
    It works for sooo many, what am I doing wrong.
    Tried everything with the desktop version, the lite version, with WiFi and with a LAN cable.
    lg. A.Graf

    1. Hi Achim,
      I can't really make sense of it right now. (Also because I don't use Airmusic and co).
      But it sounds a bit like the Shairport client on the Raspi is crashing and restarting. Can you please check the journal (the logger output of the process) and post it here?
      You should be able to view it with the following command “sudo journalctl -f -u shairport-sync”. It's best to start the journal and then try to connect. Maybe. you can already see what happened there. 🙂
      Best regards
      Fabian

  2. Hello Fabian,
    Thank you very much for taking care of the matter.
    Since I have my problems transferring the text from the terminal, I write it in here, it repeats itself 8x until Airmusic gives up.
    Each line is preceded by the Raspi name with the following “systemd[1]:”
    but that's probably always the case.

    Started Shaiport Sync - Airplay Audio Receiver.
    shairport-sync.service: Main process exited, code=killed, status=11/SEGV
    shairport-sync.service: Failed with result 'signal'.
    shairport-sync.service: Consumed 3.099s CPU time.
    shairport-sync.service: Scheduled restart job, restart counter is at 1.
    Stopped Shairport Sync - Airplay Audio Receiver.
    shairport-sync.service: Main process ex…………. The whole thing is then repeated 7 times.

    I hope this is meaningful enough to fix the problem.
    Greetings, Achim

    1. Hi Achim,
      Alright, looks like my initial suspicion is confirmed. The Shairport service seems to crash when you try to connect.
      Unfortunately, the current LogLevel does not give you a correct statement as to why this is happening. So we need to increase the LogLevel.
      You have to adapt the service file a bit for this.
      To do this, enter the following
      sudo nano /lib/systemd/system/shairport-sync.service
      and change the line
      ExecStart=/usr/bin/shairport-sync –daemon $DAEMON_ARGS
      to
      ExecStart=/usr/bin/shairport-sync -vvv –daemon $DAEMON_ARGS
      (So you just need to add the “-vvv”.)
      Then please run the following command to reload the service file:
      sudo systemctl daemon-reload
      Now you should start the journal of the shairport service again “sudo journalctl -f -u shairport-sync”.
      The best thing to do now is to open another SSH connection/terminal and then restart the Shaiport service with “sudo systemctl restart shairport-sync”. You should now see more information in the journal.
      Please try to connect to the Shairport server again. Now the output in the journal should be much more detailed.
      Then copy the issue of the journal here again. 🙂
      (How to copy text in putty is also described here, for example: https://www.alphr.com/copy-paste-putty/)
      Best regards
      Fabian

  3. // Content .service file:

    [unit]
    Description=Shairport Sync - AirPlay Audio Receiver
    Documentation=man:shairport-sync(7)
    Documentation=file:///usr/share/doc/shairport-sync/README.md.gz
    Documentation=https://github.com/mikebrady/shairport-sync
    After=sound.target
    Requires=avahi-daemon.service
    After=avahi-daemon.service
    Wants=network-online.target
    After=network.target network-online.target

    [Service]
    type=simple
    Restart=on failure
    EnvironmentFile=-/etc/default/shairport-sync
    ExecStart=/usr/bin/shairport-sync $DAEMON_ARGS
    User=shairport-sync
    Group=shairport-sync

    [Install]
    WantedBy=multi-user.target

    ——————————————————————————

    // After entering -vvv but without -daemon , because it doesn't exist in the original.
    // ExecStart=/usr/bin/shairport-sync -vvv $DAEMON_ARGS

    login as: guido
    guido@192.168.188.47's password:
    Linux Bestatt02 5.15.56-v7+ #1575 SMP Fri Jul 22 20:28:11 BST 2022 armv7l

    The included programs with the Debian GNU/Linux system are free software;
    the exact distribution terms for each program are described in the
    individual files in /usr/share/doc/*/copyright.

    Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
    permitted by applicable law.
    Last login: Wed Aug 17 10:25:33 2022
    guido@Bestatt02:~ $ sudo nano /lib/systemd/system/shairport-sync.service
    guido@Bestatt02:~ $ sudo journalctl -f -u shairport-sync // .service file edited.
    guido@Bestatt02:~ $ sudo systemctl daemon-reload
    — Journal begins at Mon 2022-04-04 14:05:58 CEST. —
    Aug 17 10:25:33 Bestatt02 systemd[1]: Started Shairport Sync – AirPlay Audio Receiver.
    Aug 17 10:25:33 Bestatt02 systemd[689]: shairport-sync.service: Failed to locate executable /usr/bin/shairport-sync-vvv: No such file or directory
    Aug 17 10:25:33 Bestatt02 systemd[689]: shairport-sync.service: Failed at step EXEC spawning /usr/bin/shairport-sync-vvv: No such file or directory
    Aug 17 10:25:33 Bestatt02 systemd[1]: shairport-sync.service: Main process exited, code=exited, status=203/EXEC
    Aug 17 10:25:33 Bestatt02 systemd[1]: shairport-sync.service: Failed with result 'exit-code'.
    Aug 17 10:25:33 Bestatt02 systemd[1]: shairport-sync.service: Scheduled restart job, restart counter is at 5.
    Aug 17 10:25:33 Bestatt02 systemd[1]: Stopped Shairport Sync – AirPlay Audio Receiver.
    Aug 17 10:25:33 Bestatt02 systemd[1]: shairport-sync.service: Start request repeated too quickly.
    Aug 17 10:25:33 Bestatt02 systemd[1]: shairport-sync.service: Failed with result 'exit-code'.
    Aug 17 10:25:33 Bestatt02 systemd[1]: Failed to start Shairport Sync – AirPlay Audio Receiver.
    ^C
    guido@Bestatt02:~ $

    // restart Raspi
    —————————————————————————————————-

    now with “-vvv –daemon”

    guido@Bestatt02:~ $ sudo nano /lib/systemd/system/shairport-sync.service
    guido@Bestatt02:~ $ sudo systemctl daemon-reload
    guido@Bestatt02:~ $ sudo journalctl -f -u shairport-sync
    — Journal begins at Mon 2022-04-04 14:05:58 CEST. —
    Aug 17 10:25:33 Bestatt02 systemd[1]: Started Shairport Sync – AirPlay Audio Receiver.
    Aug 17 10:25:33 Bestatt02 systemd[689]: shairport-sync.service: Failed to locate executable /usr/bin/shairport-sync-vvv: No such file or directory
    Aug 17 10:25:33 Bestatt02 systemd[689]: shairport-sync.service: Failed at step EXEC spawning /usr/bin/shairport-sync-vvv: No such file or directory
    Aug 17 10:25:33 Bestatt02 systemd[1]: shairport-sync.service: Main process exited, code=exited, status=203/EXEC
    Aug 17 10:25:33 Bestatt02 systemd[1]: shairport-sync.service: Failed with result 'exit-code'.
    Aug 17 10:25:33 Bestatt02 systemd[1]: shairport-sync.service: Scheduled restart job, restart counter is at 5.
    Aug 17 10:25:33 Bestatt02 systemd[1]: Stopped Shairport Sync – AirPlay Audio Receiver.
    Aug 17 10:25:33 Bestatt02 systemd[1]: shairport-sync.service: Start request repeated too quickly.
    Aug 17 10:25:33 Bestatt02 systemd[1]: shairport-sync.service: Failed with result 'exit-code'.
    Aug 17 10:25:33 Bestatt02 systemd[1]: Failed to start Shairport Sync – AirPlay Audio Receiver.
    ^C
    guido@Bestatt02:~ $

    // checked the .service part again in nano, everything is correct ... I hope.

    [Service]
    type=simple
    Restart=on failure
    EnvironmentFile=-/etc/default/shairport-sync
    ExecStart=/usr/bin/shairport-sync -vvv -daemon $DAEMON_ARGS
    User=shairport-sync
    Group=shairport-sync

    // same error message
    // I can't get any further
    greets achim

    1. Hi Achim,

      The problem is probably because there is a missing space before the “-vvv”.
      In the line “Aug 17 10:25:33 Bestatt02 systemd[689]: shairport-sync.service: Failed to locate executable /usr/bin/shairport-sync-vvv: No such file or directory”
      you can see that it is trying to execute the command “shairport-sync-vvv”. The “-vvv” parameter is therefore interpreted as part of the file name and not as a parameter.
      Please check again whether there is actually a space between the parts “/usr/bin/shairport-sync” and “-vvv”. 🙂
      Best regards
      Fabian

  4. Sorry, just wanted to say thank you for putting so much effort into it.
    Unfortunately, the thing with the extended log doesn't seem to work for me, I don't know if there are too many spaces in it, I'm not that familiar with the syntax, but try not to make any incorrect entries.

    In addition, setting via reCaptcha is a horror. I never know what that stupid button on the bottom right of me wants, mostly only works at 3 or 4x and then I never know why it worked...grrr.

  5. Hello Fabian, this site is a disaster.
    I've now tried 3x to send a text, which apparently worked after x attempts, but every time I call up the page after a few hours, my comment has disappeared.
    This must be related to the reCAPTCHA, I don't get a prompt to click on any stuff, fire alarm, bicycle, etc., hopefully this won't get lost again. If I send you one of my forum email addresses and we exchange it for my sane one via email, can we communicate through it?
    Only if you still want to help me with the problem.
    Greetings achim

    1. Hi Achim,
      the site is working and your comments have all arrived. But I have to activate the individual comments.
      Unfortunately, there is no other way, since the comment columns are pasted up several times a day by spambots.
      I try to look at your problem during the day.
      Best regards
      Fab

  6. Hi Fab,
    new update, after I went to a wine festival last weekend and immediately caught Corona, it took me a week to get by again.
    Got to work with new energy and tried to activate the extended journal again.
    Both Raspis switched on and noticed with a stupid face that both immediately connected to Airmusic on the Fire tablet after booting up.
    Without Flaks, I've had the parts since August 18th. not touched, there's no such thing, is there?
    It's nice that it works but it doesn't satisfy me because I don't know why...
    Don't want to annoy you any further with the mystical doing of the Raspis.
    Thank you very much for your patience, you have given me the confirmation all along that it will eventually work.
    However, I didn't think it would work like that.
    Have a nice time.
    Greetings, Achim

Kommentar hinterlassen

Your email address will not be published. Erforderliche Felder sind mit * markiert

This site uses Akismet to reduce spam. Learn how your comment data is processed.