title: AVPictureInPictureController doesn't automatically start picture-in-picture when backgrounding the app
body: <p>When creating a custom video player using the <code>AVPlayer</code> + <code>AVPlayerLayer</code> + <code>AVPictureInPictureController</code> for a iPhone running iOS 14 (beta 7) the video does not automatically enter picture-in-picture-mode when the app enters the background after <code>player.start()</code> is called from a UIButton action.</p>
  <p>The issue does not reproduce using the <code>AVPlayerViewController</code> which seems to indicate a problem with the <code>AVPictureInPictureController</code> on iOS 14 in general, but I was wondering if anyone else had run into this problem and know of any workarounds. I've also filed this problem with Apple under <code>rdar://8620271</code></p>
  <p>Sample code.</p>
  <pre class="lang-swift prettyprint-override"><code>import UIKit
  import AVFoundation
  import AVKit
  
  class ViewController: UIViewController {
      private let player = AVPlayer(url: URL(string: &quot;https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4&quot;)!)
      private var pictureInPictureController: AVPictureInPictureController!
      private var playerView: PlayerView!
      private var playButton: UIButton!
      
      override func viewDidLoad() {
          super.viewDidLoad()
  
          playerView = PlayerView(frame: CGRect(x: 0, y: 44, width: view.bounds.width, height: 200))
          playerView.backgroundColor = .black
          playerView.playerLayer.player = player
          view.addSubview(playerView)
  
          playButton = UIButton(frame: CGRect(x: view.bounds.midX - 50, y: playerView.frame.maxY + 20, width: 100, height: 22))
          playButton.setTitleColor(.blue, for: .normal)
          playButton.setTitle(&quot;Play&quot;, for: .normal)
          playButton.addTarget(self, action: #selector(play), for: .touchUpInside)
          view.addSubview(playButton)
  
          pictureInPictureController = AVPictureInPictureController(playerLayer: playerView.playerLayer)
  
          do {
              let audioSession = AVAudioSession.sharedInstance()
              try audioSession.setCategory(.playback)
              try audioSession.setMode(.moviePlayback)
              try audioSession.setActive(true)
          } catch let e {
              print(e.localizedDescription)
          }
      }
  
      @objc func play() {
          player.play()
      }
  }
  
  class PlayerView: UIView {
      override class var layerClass: AnyClass {
          return AVPlayerLayer.self
      }
  
      var playerLayer: AVPlayerLayer! {
          return layer as? AVPlayerLayer
      }
  }
  </code></pre>