Article

Getting AirPlay 2 into Your App

Set up your app to use AirPlay 2 to send content wirelessly.

Overview

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 AVAudioSession’s route-sharing policy parameter to .longForm. 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.

Listing 1

Set route-sharing policy parameter.

let audioSession = AVAudioSession.sharedInstance()
try audioSession.setRouteSharingPolicy(.longForm)

Add an AirPlay Picker to Your App

Add AVRoutePickerView 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 AVRouteDetector 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 MPRemoteCommandCenter, you can receive remote commands. If you use MPNowPlayingInfoCenter, 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:

See Also

Getting Started

Implementing Simple Enhanced Buffering for Your Content

Configure your app for simple enhanced buffering to stream content faster to your AirPlay-enabled device.

Implementing Flexible Enhanced Buffering for Your Content

Configure your app for flexible enhanced buffering to stream content faster to your AirPlay-enabled device.

Playing Custom Audio with Your Own Player

Construct an audio player to play your custom audio data, and optionally take advantage of the advanced features of AirPlay 2.

Integrating AirPlay for Long-Form Video Apps

Integrate AirPlay features and implement a dedicated external playback experience by preparing the routing system for long-form video playback.