1

I have followed Apple's steps in order to get my AVPlayerViewController to support in-app and background Picture in Picture playback.

func playerViewController(_ playerViewController: AVPlayerViewController, restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: @escaping (Bool) -> Void) {
    present(playerViewController, animated: true) {
        completionHandler(false)
    }
}

The button shows on iPad, but not on iPhone, and video playback does not continue when going to the home screen.

Ricky
  • 3,101
  • 1
  • 25
  • 33

1 Answers1

0

Further to implementing the required AVPlayerViewControllerDelegate, you also need to ensure you are setting the right audio session category, like so:

let audioSession = AVAudioSession.sharedInstance()
do {
    try audioSession.setCategory(.playback)
} catch {
    print("Setting category to AVAudioSessionCategoryPlayback failed.")
}
Ricky
  • 3,101
  • 1
  • 25
  • 33