AirPlay Implementation in AVPlayer

Pratheesh Bennet
Towards Dev
Published in
Feb 17, 2022

--

Hey all, today we are going to see a simple and straightforward implementation of AirPlay when using custom player controls as it is totally free with the AVPlayerViewController

To implement AirPlay routing we use AVRoutePickerView class. AVRoutePickerView is a subclass of UIView that displays control for picking playback routes.

  1. Enable AirPlay in the Background Mode under targets -> Signing & Capabilities

2. In order to make AVRoutePickerView detect external routes, we have to enable the allowsExternalPlayback property of the AVPlayer to true

3. Add the AVRoutePickerView instance to the view. AVRoutePickerView provides the system AirPlay icon.

routePickerViewWillBeginPresentingRoutes, routePickerViewDidEndPresentingRoutes are the delegates provided by the AVRoutePickerView

As simple as that. You have implemented AirPlay in your custom control. Please feel to reach me at pratheesh_db@hotmail.com for any help or queries in Swift. Happy coding!!

--

--

Product owner Falcon Forms (www.falconforms.app). Digitize your paperwork using Falcon Forms. Build and configure your own forms in an instant.