Hacker News new | comments | ask | show | jobs | submit login
Apple Airplay on Raspberry Pi in 7 Easy Steps (appcodelabs.com)
295 points by 3chelon 37 days ago | hide | past | web | favorite | 111 comments



At the risk of being a bit off topic … A lot of people interested in Airplay will be looking at this post wondering how to use AirPlay with UPnP or ChromeCast devices. shairport-sync [1] (used in the article) only works directly with audio hardware, so won't work with Chromecast or UPnP compatible systems. I've tried many many different open-source bridges and finally found AirConnect [2] which is by far the most reliable, active and well-maintained bridge. philippe44 responds to every issue filed (as far as I can tell). Works great with my Sonos PLAY:1 & XBox.

[1] https://github.com/mikebrady/shairport-sync [2] https://github.com/philippe44/AirConnect


Thats exactly what I used. Highly recommend AirConnect.


Mind sharing some details on how you got it to work with XBox?


My beef with airplay and pretty much every other Zeroconf based service is that they require weird stuff to work across subnets. Here I isolate every “IOT” device specially the ones that potentially has a phone home capability into a separate network. The wireless network is also segregated and routed. To make everything Zeroconf/Bonjour work I have to create lots of SRV, PTR and TXT records in my internal DNS which is a Samba4 AD. This document http://www.grouplogic.com/Knowledge/PDFUpload/Info/WanBonjou... is great to setup the basics but you will have to find out the specific RR for each type of service.


You could also set up Avahi or some other mDNS daemon to relay mDNS packets across the two different networks, so long as you can route the UDP/IP from one network to another you shouldn't need to create a whole bunch of TXT records.


Going DNS has its advantages like being a less broadcasty solution that can work across VPNs. I've first implemented it some years ago when a client wanted to share authenticated wireless AirPrint to wireless guests on his huge school wireless network. The system is still working.

I guess another advantages of going DNS besides not having to broadcast information is that you chose what you want to publish.


Here is an article about mDNS and bonjour:

https://community.cisco.com/t5/wireless-mobility-documents/b...

However it is not particularly clear!


Indeed. The usual term for this is a “mDNS Reflector”.

There’s a guide for setting it up with Avahi here: http://chrisreinking.com/need-bonjour-across-vlans-set-up-an...


This guy must have been doing this at exactly the same time as me. I used shairport-sync and whilst I eventually got it working last week it wasn't plain sailing. Getting the service setup to start upon powerup was a real pain in the ass. I've also had to move it onto a separate wifi network as an RPi camera was hogging the bandwidth which caused audio dropouts on the shairplay-sync server.

Also as many of you will probably comment, the Rpi audio out stage is awful. I'm waiting for my Dad to return my USB soundcard so I can use that instead of the headphone socket on the Pi.


Absolutely. I'm the article author and yes, adding a DAC is definitely recommended because the output from the audio jack is terrible.

I'm intending to do a follow-up article on this, but so far I've tried IQAudIO Pi-DAC+ with an RPi 3A+ and HifiBerry DAC+ Zero on a Zero W. I was extremely surprised by the good quality of the HifiBerry.


I noticed the writeup has your output set at +4db. That implies it’s substantially overdriving the output, which will cause obvious distortion. I have a rpi plugged into my high-end-ish stereo for other reasons, and find the output to be more than good enough.

If you’re complaining about audiophile nuances like warmth and presence, and also using 24-bit, high sample rate audio files, then fine, but if you’re encountering obvious distortion or buzzing then something’s wrong with your setup.

(Thanks for writing this up, by the way; it didn’t occur to me that I could set up an AirPlay server with stuff I have laying around.)

[edit: I forgot that I’m using hdmi audio. Still, the +4db thing is a red flag]


HDMI audio from the Pi is fine. It’s analogue audio from the 3.5mm TRRS connector where the sound quality is poor, quiet and hissy.

I first discovered how bad it was building a bespoke car stereo out of a Raspberry Pi 1 - and ended up buying a USB DAC because of it. But it seems to still be an issue even in the later boards because emulation forums are often talking about using HDMI or an addon board for RGB+Stereo if your display doesn’t support HDMI.


4dB is the default setting for the built in audio set to 100%. And yes it sounds quite horrible, but the internal audio does in general.

When you add a DAC that is fixed and it changes to the correct setting of 0dB.


Doesn't the (analogue) audio have better isolation on more recent pi models?


Great! I'm hoping that my Behringer UCA202 will do the trick.


How has it managed to escape me, immersed in tech every day for many years, that there is such a thing as a USB soundcard? Crazy how things can slip through the cracks, be so close yet missed.


They're definitely useful. Also, even at the low end, often better than onboard simply because they get so much less interference. There are also some really nice higher end options if you ever want to do multi-channel mixing/capture.

Aside: for anyone considering a hackintosh, USB audio is about your best bet in this space.


Note these are often called by other names ('soundcard' is not very descriptive to me because they look nothing like the PCI cards you're imagining installing in your desktop PC). A 'USB audio adapter' or 'USB DAC' are the same thing.


They're the same thing as the headphone dongles that most new phones these days need to output audio.


They usually work with your phone as well


There are tons of them too with all kinds of different attributes (multi channel, spdif, etc)


I made a Shairport server for 6 audio zones years ago on an ancient desktop computer and multiple PCI sound cards. After it died, it was hard to migrate to a single Raspberry Pi due to the USB audio cards devices scrambling on each boot (so the kitchen may become the living room, etc.).


This can be solved in a udev rule [1]. For example, this is a rule I use to always bind my P1 (smart energy meter) at the same port:

  KERNEL=="ttyUSB[0-9]*", ATTRS{interface}=="P1 Converter Cable", NAME="%k", SYMLINK="USBP1Cable", GROUP="tty", MODE="0660"
[1] /etc/udev/rules.d/50-ttypermissions.rules


Thank you! I'm going to take another look and try to get this set up. Looks like udev and device paths will do it:

https://stackoverflow.com/questions/43361613/how-can-i-ident...


Shairport-sync also has small audio glitches, and I ended buying an airport express. Certainly cheaper than buying a raspberry pi and good DAC. The airport express DAC is very good.


And a recent-ish firmware update for them enabled AirPlay2, so I can now stream to all three of my Airport Expresses in sync from my phone or iPad. I was quite pleasantly surprised by Apple still providing useful software updates to hardware they no longer sell (I'm guessing the probably won't push an AirPlay2 update =for my original AppleTV though, since they'd prefer I upgrade it to a newer one which they're still selling...)



I mean, you say "new" but it's been around for over a year. And it's a huge improvement. Are all the people here complaining about audio quality, complaining about this improved driver or the original poor driver? My ears are not great but I find the new one very usable with an amp; it's not great with headphones but that's hardly surprising.


That's strange to me as well. The new driver continues to sound awesome for me, so hmmm...


I've been doing this for a couple years with a Zero (pre-W) and a pHAT DAC[0] with great success.

It just runs and reliably shows me a Airplay device for my garage speakers. I recommend it for people who have audio hardware lying around and don't want to replace it with more expensive and worse sounding smart speakers.

0: https://shop.pimoroni.com/products/phat-dac


It's a bit funny how the best way to stream audio between two Linux boxes is Airplay with shairport on the server and the raop2 PulseAudio Plugin on the Client. It integrates well into the Desktop too and is automatically discovered!

It's funny because PulseAudio could do network streaming itself, but as it still streams the uncompressed PCM stream afaik, it's pretty useless in practice.


Adding to this, DLNA from Linux (pulseaudio-dlna) to a Raspberry PI is also a lot slower than the using AirPlay in the way you described… :|

(By "slower" I mean that there's a significant delay.)


We're using the PA PCM method in our student association. Works good enough.


I reckon you have everything connected over Ethernet then?


No, WiFi.


You can also just buy an old Airport Express base station and repurpose it for AirPlay. The old 802.11g ones can be found for about $10 or so and even have an optical audio out.


I went this route. Nightmare. The installer software has been removed for Mac and isn't available anywhere. Had to find a laptop running Windows 7 to get it up and running. It also won't be compatible with modern routers. 1/10 can not recommend.


Yep. I was fortunate to have an old iLamp that can't handle the current version of the Airport Utility software, which doesn't support the older Airport Express (Mine are branded "AirMac," because I bought them in Japan) base stations.

You can get Airport Expresses on Goodwill for $5 to $10, but you need an old machine to set it up.

The current version of Airport Utility will see them in an extended network, and plot them on the network graph, but can't be used for configuration.


Eh? Are you talking about this https://support.apple.com/kb/DL1664?viewlocale=en_US&locale=... - also available for iOS?

It's still there. I have an Airport Extreme that very happily updated itself to support Airplay 2 a few months again


It no longer supports the original Airport Express, the one that can be had on Craigslist for $10.


There is (was?) a workaround to get the old Airport Utility management software to still work. But in the end I gave I and just replaced that old one with one of the more recent ones. (If anyone in Sydney .au wants the old one, shout out...)


Apologies.


I wasn't aware that recent versions of Airport Utility don't support the 802.11g Airport Express. That's annoying.

But why wouldn't it work with modern routers? As far as I know, even the newest WiFi routers still support 802.11g clients.


Might be mis-remembering, this was 4-5 years ago. Had to do some trickery to get it to see my network in the old version of Airport Utility.


What do you mean by "won't be compatible with modern routers"? Are you referring to the 802.11g? These devices had an ethernet port, IIRC. I'm sure I remember plugging mine into my network and not using its built-in wifi.


Yes, they have an ethernet port, but the goal of such a device (for me, where I don't have ethernet running to my speakers) is to stream music over wifi.


I know modern waps can disable 11a and 11b to make 11n (and later) faster, but I thought 11g was safe.


All the Airplay tutorials I've seen are about being a receiver for Airplay signals from something like an iPhone. These boxes then plug into speakers for output.

Does anyone know if there are tutorials on making an Airplay client that instead sends audio & video to a receiver of some type (e.g. Apple TV)?


This project can stream audio to an Apple TV and includes details about the (now required) pairing protocol: https://github.com/philippe44/RAOP-Player


Thank you!


My understanding is that this is possible because at some point, the private keys for the airplay encryption were found. Alas airplay 2 cannot be supported unless the same thing happens, which is a shame.


I suppose these guys have it figured out since their product supports the HomePod?

https://www.rogueamoeba.com/airfoil/


What's the difference between airplay 1 and 2?

Is it quality?


I couldn't quickly find a detailed breakdown, but here's a basic one:

- Airplay doesn't offer multi-room audio; AirPlay 2 does

- AirPlay lets you stream from any Apple device to your speakers or TV

- AirPlay 2 lets you play from speakers over Wi-Fi, and it'll stay in sync

- AirPlay 2 lets play different songs in different rooms with multiple HomePods

If memory serves, the original AirPlay had much simpler goals. Stream music from a single computer to a speaker over a local network. So it has concessions like a constant 2 second lag, which happens if you press pause/play. I vaguely remember other weird restrictions when playing with it in the past (like one device at a time had to control a speaker).

AirPlay2 is a lot more complex adding the features mentioned above and better handling the use-cases original AirPlay grew into.

https://www.pocket-lint.com/speakers/news/apple/144646-apple...


The big difference for me, is that I can select any combination or all of my AirPlay2 devices from my phone, but I can only select a single airplay (1) device and nothing else at the same time. (For me, that means my old AppleTV can be selected, but nothing else at the same time, but any combination of my three Airport Expresses can be selected.)


In addition to the other features mentioned, I believe AirPlay 2 supports more media formats and more precise control over playback, and more metadata about the media playing.


Multi-room streaming and better lock-in to prevent projects like this one from being possible with open source.


I wonder if there was a way to answer that without editorializing. There's nothing stopping someone from coming up with an open source streaming platform, it just won't be embedded in iOS.


You mean it won't work with Apple owned device because Apple does not permit you to do so?


No I don't mean that, when there are things like Chromecast that let me pick content on my iOS device and see or hear it on my TV or stereo.


I feel like you editorialized kevin_b_er. Obviously they were talking about Apple preventing this software with working with the new airplay system. Where were they saying it's impossible to come up open source streaming protocol?


Airplay 2 haas reduced latency and improved quality. You can also stream to multiple Airplay 2 devices from iOS while iTunes on a Mac/PC can stream to multiple Airplay 1 devices.


In a nutshell, AirPlay 2 decouples the media and the control streams.

This makes play/pause etc instant (rather than waiting for the 3 second buffer to run out) and makes it much easier to do multi-speaker audio as they're all listening to the same media stream.


If you want to do the same for Chromecast it's not possible yet. Google seems to have locked down their API. There is some open-source projects that are trying to reverse engineer it but the problem seems to be linked to crypto keys used to authenticate real Chromecast devices: https://github.com/thibauts/node-castv2/issues/2


And Google do security pretty well, so it's unlikely the certs will be leaked or broken :( When the Chromecast first came out, the was an open source receiver called leapcast which reverse engineered the DIAL protocol that the YouTube app on many smart TVs of the day used, and the Chromecast protocol was based on. But alas it doesn't work anymore.


The Raspberry Pi has awful noisy audio out. There are some nice Amps you can get like the HiFi Berry. I set up a nice arrangement in my old lab with with these.


Another vote for the HiFiBerry. I’ve used their Digi+ board (which includes optical-out) with a Pi3B running Volumio for a couple years and it’s been fantastic.


I'm using a generic HiFiBerry clone that I got for $18 with a pi3b running Volumio as well. I'm using a 240GB SSD in a USB enclosure as the drive, and a cron job that keeps it synced with my fileserver. Only snag was finding a power supply that could reliably provide enough power, I've settled on an Apple ipad charger I had laying around. It's been great for a few months now. Sound quality is very good.


Good power adapter options for the Pi is definitely one of my bigger complaints. Even determining a good one to get from Amazon is painful, considering how many cheap/knockoff options are out there.

If a company could get the kit price under $40-50, I would definitely use them for more one-off projects. Aside, I really wish that Docker for (Windows|Mac) ran as a service without requiring login so I could run background linux software with a little less friction. The linux on windows stuff is coming along, but similarly lacking initd/systemd startup. And while I know that a desktop os isn't a server, I've got a plenty powerful desktop that I have always on, and would just assume not have another computer running.


I just use HDMI to connect it to audio receiver.


Yes the HifiBerry is very very good for the price.


Been running Shairport Sync on a Pi3 for the last couple of years. It works great.

I've been adding more stuff to the Pi over time, so it's now a Plex server, Home Assistant hub, Torrent box, Pi-hole and more.


I did the same thing a couple of weeks ago using a Raspberry Pi 3 B+. I have it connected to a Cambridge Audio stereo amplifier through USB, since the amplifier has an integrated DAC. I'm very pleased with it, and it was surprisingly easy to get working.


Nice idea. My amp is Cambridge Audio but it sadly does not have a DAC. If it had, the setup would have been even simpler than it is.


Did the opposite a few months ago, and used a Raspberry Pi Zero to AirPlay audio from my turntable to a HomePod. It was about as amazingly useless as one would imagine, but fun none the less.


Wow, I'd love to see a write-up of that.



If anyone is looking for multi room audio (like airplay 2), using raspberry pies, this is the best solution I’ve seen - it is really impressive:

https://www.reddit.com/r/homebridge/comments/8v3qb0/shairpor...

If people have other suggestions for multi room audio I’d love to see them.


I'm still using squeezebox and really like the original hardware, plus home made receivers using pi's; it's a fully open source media system - something that doesn't seem to exist in today's landscape of vendor lock in.

Nonetheless, it's showing its age somewhat, and is harder to get streaming services working on it (e.g. YouTube, play music) in part due to its open nature (also, it's written in Perl...)


Have you ever used the grouped rooms feature mentioned in that reddit comment? Seems pretty cool.


No, but now that I've seen it I'll be trying it out :)


Never discount the simplicity and reliability of a (legal) low power FM transmitter.


I attempted using an FM transmitter but I had 2 issues

1) I think my transmitter was a little noisy so that wasn’t desirable.

2) I didn’t have a nice FM receiver to test with, but didn’t want to purchase one because I thought my transmitter was noisy. So a bit of a catch 22.

But FM would be great.


Where can you get/make one with decent audio quality and stable frequency?


It's overkill to use a Raspberry Pi for this.

I made a dozen Airport adapters with the TP-Link WR710N which was $25 at the time and connects to Wifi or ethernet. Add a USB soundcard ($10?) for powered speakers or a Topping USB amp ($75?) for unpowered speakers. Install OpenWRT, connect it to your network in client or bridge mode, install the built-in shairport-sync package, and go.

Not sure what has replaced the WR710N but I'm sure you can still do this just as cheaply.


To be fair, a Pi Zero W costs less than £10, or the equivalent in dollars.


I'm a big fan of RasPis, but people _always_ understate the real costs.

That TPLink wifi router comes in a case with a (probably shitty but working) power supply and cable, and inbuilt flash memory.

A Pi Zero costs ten quid, but you need to add a case, a power supply, and a micro SD Card. But worst for me, is that they still limit you to buying one at a time, so if your decide "Hell yeah! 5 room wi-fi streamed audio sounds _Awesome!_" You're not only up for fifty quid for the Pi Zeros, but you're gonna spend at something like twice that much again for 5 half-decent power supplies, USB cables for the power supplies, SD cards, and cases, and then you're up for 5 lots of shipping charges because they aren't allowed to sell you 5 Pi Zeros in one order... All of a sudden that "fifty quid project!" has become a £150+ one in five seperate deliveries...

(And unless you don't care too much about the audio quality, both the Pi Zero and the TPLink router will need a better external DAC anyway...)

If you just want one, and you're the sort of person who has usb power supplies, cables, sd cards kicking around doing nothing, and you're not too fussed about having a nice case, sure, you can just order one ten quid Pi Zero plus 3 quid for shipping.


It does, sort of, but, if you want to do this seriously, as in, you want more than one unit (I wan't ~5 to add to the open-source home security camera software I'm writing), you can't buy more than one at a time unless you buy it with headers attached (which I don't want), leaving you the alternative of buying them individually and paying for delivery for each individual unit.


Micro Center has them for $5 for the first unit, $15 for units 2-5, and $20 each after that. Still less than ideal but not too bad.


Seems like a better deal than we get here in the UK.

These £9 Pi's rarely go for less than £12-14 and if you can get more than one, they won't be any cheaper.


I love a good excuse to buy more RPis and have thought about doing something like this.

However, I already have a cheap bluetooth dongle that I plugged my stereo to via P2. Is there some advantage to this setup (beyond range)?

What I'm really considering is a web interface, with search, playlist etc and a huge SDcard with all my music connected to a RPi. Currently all my music is on my Mac and Apple Music Home Share is a bit flaky/slow at times.


Check out mopidy.


My take on this was :

1- Buy hardware (Raspberry + DAC + Amplifier)

2- Download and install Volumio (volumio.org) on SD card

3- Profit


What do you advise for a baseline DAC+Amplifier?


My setups are pretty cheap as I did not want to put much money in it.

As for DACs, I have a €24 Hifiberry DAC+ and an inexpensive raspberry compatible DAC out of Aliexpress (around €12) on my two different setups (kitchen and living room). Both work well and deliver good enough signal (I am not by anyway an "audiophile") I prefer the no-brand one from AE though as it has an IR receiver I am using to control media playing.

As for amplifiers, any stereo amplifier would work, so I choose a Lepai lp-2020a (€30 on amazon) in the kitchen. I have an old Marantz branded amplifier for the living room.


Could not agree more.


Nice! I'm trying to do it the other way around, record player into Raspberry Pi, broadcast to my HomePod. Unfortunately the only way it works is to add a laptop in between. If anyone has managed to get an AirPlay broadcast from Linux I'd love to know how you did it!


Have a look on GitHub, there's quite a few projects. Pulseaudio can also stream over Airplay 1 and 2.


I bought a Google Chromecast Audio. Spotify, Soundcloud and Pocket Casts support it on iOS. I'm not actually sure what the officially Apple sanctioned way of getting audio to my speakers is, but I haven't felt the need to find out either.


I had one of those devices and it worked great but now I just don’t want google knowing my listening habits so have gotten rid of it.


Mike Brady has done a great job with this. The project also has a very detailed readme, far beyond what most provide. Thanks Mike for all your efforts.

I'm not sure this how-to article adds that much but I guess it's nice and simple looking.


I use shairport-sync on my iMac to stream Overcast from the iPhone. There is a huge latency and the connection drops out every once in a while. This should have been a built in feature.


While not an iOS user, it is definitely cool how many one off projects you can create using Raspberry Pi. I do wish some of the full kits (case, power adapter, micro sd) would come down in pricing slightly as it tends to bump up towards more powerful, but less supported (and more difficult) options when you consider the full system price.


Depending on the project, Raspberry Pi Zero W is often powerful enough. $5 on sale at Microcenter, $4 for the case.


This is a cool project, and I think it can be a good addition to an existing home media server.

For the use-case they describe however (wiring up an existing home stereo) it would probably be a lot easier and better supported to just buy an Airport Express.

You can still buy them online for ~100, and they support Airplay2 as well, which is much nicer for multi-room audio.


It appears this is Airplay 1 only (please correct me if I'm wrong) so this will not be as nice as say, using an Airport Express but if you had this stuff laying around it might be worth it.


For those using Spotify premium for listening to music there are some open source projects (like spotifyd) that replace the now deprecated spotify-connect.


Does anyone have suggestions for the reverse? basically an analog input (turn table/cassette) that can be streamed over wifi as digital output


Not wifi, but you could get an aux to bluetooth adapter:

https://www.amazon.com/GOgroove-BlueSENSE-Bluetooth-Transmit...


Should also mention this does not support video.


These work too for $30 https://www.amazon.com/dp/B01HFYZDNC/ but it might be a security threat to have them on your LAN, I have no idea what software they run.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: