As of Mac OS 10.8 (Mountain Lion) apps have the ability to send audio to airplay devices. If an airplay device is available Mac OS will provide a new audio device named “Airplay” with a transport type of kAudioDeviceTransportTypeAirPlay. If this airplay audio device is selected for playback by an application, coreaudio will send the audio over the network to the physical airplay device. This happens completely transparent for the app. It only needs to open the airplay audio device and coreaudio does the magic.
If there is more than one physical airplay device available coreaudio will send audio only to the first, default device. But it is possible for an application to tell coreaudio which physical airplay devices should be selected for playback. Even multiple devices at once can be selected. Each physical airplay device corresponds to one data source of the Mac OS airplay audio device. It is possible to find out the names of these data sources and it is also possible to select multiple data sources for playback.
I have hacked the JUCE coreaudio audio device to make it possible to control airplay devices in this way. Please find attached the changed files and a small example project that demonstrates how to use them.
A few things are still missing and would still need to be implemented are:
- JUCE should inform clients that the available devices have changed. This is because airplay devices can be turned on and off at any time. When no physical airplay device is visible anymore the airplay audio device will no longer be available. This may already be implemented through the device manager and its change callbacks.
- JUCE should inform clients that the available data sources of a device have changed throught some callback mechanism. If there are multiple airplay devices available and one is turned off the list of available data sources will change.
What’s not possible with the available coreaudio apis as far as I can see is:
- Control the a data source volume to make it possible to adjust the relative volumes between multiple airplay devices.
- Simultaneous playback on the local machine and through airplay devices.
iTunes can do both but it seems they don’t use the airplay support that is part of the operating system but use an independent implementation of the complete airplay protocol instead.
I would love to continue working on this. Guidance how to correctly integrate this into JUCE is needed though. This is all very plattform dependend and the api changes to the JUCE AudioIODevice class should be done in a way that makes sense to other plattforms.