I'm trying to get the Airplay button to appear in the native AVPlayer controls, using the AVPlayerViewController.
I started a new project and am using the following block of sample code in viewDidAppear
:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
let videoURL = NSURL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
let player = AVPlayer(URL: videoURL!)
player.allowsExternalPlayback = true
player.usesExternalPlaybackWhileExternalScreenIsActive = true
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.presentViewController(playerViewController, animated: true) {
playerViewController.player!.play()
}
}
Just in case, I have also enabled airplay in Background Modes
. Still no luck. I have seen people saying that you need to add it as an MPVolumeView
, but this appears to be meant for custom controls. I couldn't figure out a way to add it to the native AVPlayer controls.
If anyone can provide a working example of a barebones project that has airplay button enabled in the native AVPlayer controls, I can try to reverse-engineer it to figure out what I'm doing wrong.
Thanks!
Edit: I checked out the 'iTunes Movie Trailers' app (from Apple), and am not seeing the Airplay button in their controls either. This is a pretty big red flag that either this is a bug, or that apple has removed the airplay button from the default AVPlayer controls altogether and has done a poor job of documenting this change. Can anyone point out an app that uses default AVPlayer controls that also includes the airplay button?