HowTo: Raspberry Pi – “Shairport” Airplay auf dem Raspberry Pi installieren

Jeder der ein (oder mehrere) Apple-Geräte verwendet kennt sicherlich die AirPlay-Funktion. Dank dieser lassen sich Medien aller Art an andere Geräte im Netzwerk streamen. So kann man Fotos auf einem AirPlay fähigen Fernseher anzeigen, Videos abspielen oder auch Musik auf AirPlay fähigen Lautsprechern wiedergeben.

Zumindest letzteres könnt Ihr auch ganz einfach mit einem RaspberryPi erreichen und so einen RaspberryPi zu einem AirPlay fähigen Lautsprecher umbauen.

Ich verwende diese Lösung zum Beispiel in meinem MagicMirror. So könnt Ihr den RaspberryPi (der im magicMirror) verbaut ist auch noch als Musik-Lautsprecher nutzen. 🙂

Alles was Ihr benötigt um Euren RaspberryPi so einzurichten, ist im folgenden Artikel beschrieben.


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.

Shairport installieren

Die Installation von Shairport ist dank des Paketmanagers sehr einfach.

Gebt dazu einfach folgenden Befehl in die Konsole Eures RaspberryPi ein.

sudo apt-get install shairport-sync

Eine eventuelle Nachfrage, dass dadurch Speicher belegt wird, könnt Ihr mit “Y” und “Enter” bestätigen.

Die Installation läuft dann automatisch ab.

Um Shairport nach der installation zu starten, müsst Ihr nun noch folgenden Befehl ausführen

sudo systemctl start shairport-sync


Status anzeigen

Dank des Kommandozeilentools systemctl könnt Ihr Euch leicht einen Überblick über den Status Eures Shairport-Servers verschaffen.

Gebt dazu einfach folgenden Befehl in Die Konsole Eures RaspberryPi ein.

sudo systemctl status shairport-sync

Hier könnt Ihr nun sehen, ob der Shairport-Server “active” oder “inactive” ist.


Autostart aktivieren

Damit Euer Shairport-Server auch nach einem Neustart des RaspberryPi automatisch wieder startet, solltet Ihr nun noch dessen Autostart aktiviern.

Gebt dazu einfach folgenden Befehl in die Konsole Eures RaspberryPi ein.

sudo systemctl enable shairport-sync


Musik Wiedergabe starten

Das war schon alles. Nun solltet Ihr auf Eurem iPhone (oder anderen Apple Gerät) bereits in der Lage sein Euren selbstgebauten AirPlay-Receiver nutzen zu können. 🙂

Zum Beispiel findet Ihr nun in Eurer “Podcasts”-App das gekennzeichnete Symbol.

Sobald Ihr darauf klickt…

…sollte Ein Menü geöffnet werden, in der auch Euer soeben eingerichteter AirPlay-Lautsprecher (hier “MagicMirror” genannt) angezeigt wird.

Sobald Ihr diesen anklickt, sollte die Musikwidergabe darauf starten.


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?
      Du müsstest ihn mit folgendem Befehl anzeigen können “sudo journalctl -f -u shairport-sync”. Am besten das Journal starten und dann einen Verbindungsversuch starten. Vllt. kann man dort ja schon sehen was passiert ist. 🙂
      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.
    Es steht vor jeder Zeile der Raspi Name mit folgendem ” 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
      (Du musst also nur die “-vvv” hinzufügen.)
      Then please run the following command to reload the service file:
      sudo systemctl daemon-reload
      Nun solltest du wieder das Journal des shairport Service starten “sudo journalctl -f -u shairport-sync”.
      Am besten öffnest du jetzt eine weitere SSH Verbindung/Terminal um dann den Shaiport Service mit “sudo systemctl restart shairport-sync” neu zu starten. Nun solltest du bereits mehr Informationen im Journal sehen.
      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
    —————————————————————————————————-

    jetzt mit “-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,

      das Problem liegt wohl daran, dass vor dem “-vvv” ein Leerzeichen fehlt.
      In der Zeile “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”
      kann man sehen, dass versucht wird den Befehl “shairport-sync-vvv” auszuführen. Der Parameter “-vvv” wird also als Teil des Dateinamens interpretiert und nicht als Parameter.
      Bitte prüfe hier nochmal ob zwischen den Teilen “/usr/bin/shairport-sync” und “-vvv” auch wirklich ein Leerzeichen ist. 🙂
      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.