4

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?

Four
  • 406
  • 4
  • 13
  • Is your phone connected to the same network as your airplay device? – L A May 17 '16 at 05:26
  • My phone is on the same network as my Airplay device. If I bring up the control panel by swiping up from the bottom of the device, and press the airplay button next to the airdrop button, I can see a list of my airplay devices. – Four May 17 '16 at 17:49
  • Any luck on this? I'm running into the same problem. – vtcajones Mar 20 '17 at 22:00
  • I haven't looked into this in quite some time, but at the time, we concluded that Apple had removed support for including this control in the default player. If you want an airplay button, you have to include it as a custom control outside of the default player. – Four Mar 21 '17 at 22:09

0 Answers0