I am using a custom AVPlayerLayer
to display a simple video. I am trying to add airplay support, but the button, when tapped, does not show anything.
self.player.allowsExternalPlayback = true
...
let airplayButton = MPVolumeView(frame: self.airplayButtonPlaceholder!.bounds)
airplayButton.showsRouteButton = true
airplayButton.showsVolumeSlider = false
self.airplayButtonPlaceholder?.addSubview(airplayButton)
self.airplayButtonPlaceholder?.backgroundColor = UIColor.clear
When I run my code (on a real device), I see the button, but when I tap on it, nothing happens. What could be causing this? Is it because I am using custom AVPlayerLayer
and AVPlayer
?
EDIT:
When I turn on mirroring through the control center, I can touch the button and it displays the pop up. What's going on?
Nothing happen because you haven't properly configured this "new window".
There are two ways to display content using Airplay.
Mirroring
Doesn't need any configuration.
Extra Window
(check apple guide here)
The steps as described by apple are:
Here is the code taken from the apple docs for a quick reference.
- Create a New Window If an External Display Is Already Present
- Register for Connection and Disconnection Notifications
- Handle Connection and Disconnection Notifications
EDIT:
When using an AVPlayerViewController it is already automatically implemented as described within the documentation here.