Set up your app to use AirPlay 2 to send content wirelessly.
With AirPlay 2, you can wirelessly send your content from any Apple device to a speaker enabled with AirPlay or Apple TV. AirPlay 2 includes significant enhancements for wireless audio distribution, such as sending content to multiple AirPlay-enabled speakers.
Integrating AirPlay 2 into your app is a four-step process.
Identify the Audio Type Your App Will Play
Set your app’s
AVAudio’s route-sharing policy parameter to
.long. Long-form audio is anything other than system sounds, such as music, audiobooks, or podcasts. This setting identifies the audio that is being played by your app.
Add an AirPlay Picker to Your App
AVRoute to your view hierarchy. This view adds an AirPlay picker to your app. The picker is a dialog with a list of potential AirPlay devices you can use. To control when the picker is shown, use
AVRoute to identify the state of the route detector.
Add Media Player to Your App
Use APIs to customize your AirPlay adoption with MediaPlayer integration. If you use
MPRemote, you can receive remote commands. If you use
MPNow, you can inform the system metadata about the track that is currently playing.
Configure Your App for Fast Streaming
Adopt one of two playback API sets that are designed to take advantage of the enhanced buffering in AirPlay 2:
For simple enhanced buffering, use
AVQueue. This works well for video content. See Implementing Simple Enhanced Buffering for Your Content for more about this process.
For more flexibility with enhanced buffering, use
Buffer Audio Renderer
AVSample. This option is better for apps which, for example, require more control over I/O, perform preprocessing on their media data, or have a DRM model that can’t be used with
Buffer Render Synchronizer
AVPlayer. See Implementing Flexible Enhanced Buffering for Your Content for more details on this process.