Create an Airplay 2 Player

Our house came with outdoor speakers installed but there wasn’t a way to play music on those because there wasn’t any audio receiver connected. These are passive speakers so would require an amplifier (or full blown audio receiver) to power them. Buying a receive is an overkill so I was looking for amps. While looking for amps, wanted to get one that has Airplay capabilities, but unfortunately those seem very pricey. Therefore, I decided to look for a solution that would allow one of my home servers to act as Airplay player while using a low price amp to connect to passive speakers. So ultimately, this:

Home Server (Airplay) — audio out –> Amp — audio out –> speakers

Searching the web for self-hosted Airplay server, I stumbled upon an excellent project called Shairport-sync that allows you to create an Airplay 2 audio player on a linux machine and what more to ask for then already available docker image for this. So, I ended up trying this out and it works fantastic.

Sound on linux uses alsa which was installed by default on my ubuntu server. However, you will need to install alsa-utils which will give you access to alsamixer and other tools.

sudo apt-get install alsa-utils

Then, ensure your audio device is not muted, and adjust audio volume using alsamixer.

sudo alsamixer

Ensure master volume is not muted. In my case it is set to value of 64. To increase/decrease volume, first select the device using left/right arrow keys, and then adjust volume using up/down arrow keys.

Next for shairport-sync you will need to specific a sound device, For that you will need to run the spa-alsa-explore utility.

docker run --device /dev/snd mikebrady/sps-alsa-explore

Here my sound device is hw:PCH_1 which is the analog aux output at the pack of the computer.

Then, I created the following docker-compose style code to be used with portainer (which is what I use to manage all my containers). I named the player as “Outdoor Speakers” using the command line option -a. I also specified the sound device hw:PCH_1 that shairport-sync should be using.

shairport-sync:
  image: mikebrady/shairport-sync:latest
  network_mode: host
  restart: unless-stopped
  container_name: airplay
  devices:
    - "/dev/snd"
  command: --statistics -a "Outdoor Speakers" -- -d "hw:PCH_1"
  logging:
    options:
      max-size: "200k"
      max-file: "10"

My container started without any issues. No hiccups whatsoever. I then checked on my iPhone if I can see this player, and lo and behold “Outdoor Speakers” showed up.

I then proceeded to play music to this “Outdoor Speakers” player, and voila it worked without any issues!

In summary, Shairport-sync allowed me to easily turn a linux machine into an Airplay 2 Player. Having docker image made setting up this very easily, and I had success in the first attempt itself.

Leave a Reply

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