When creating a custom video player using the AVPlayer+AVPlayerLayer+AVPictureInPictureController in iOS 14 (beta 7) the video does not automatically pip when the app enters the background if player.start() is called from a UIButton action. However if player.start() is called from viewDidLoad this is not a problem.
The issue does not reproduce using the AVPlayerViewController which seems to indicate a problem with the AVPictureInPictureController on iOS 14 in general.
The issue also did not reproduce on beta 5, but started appearing on beta 6 -- probably a iOS 14 regression.
Some sample/pseudo code to illustrate the problem.
Is anyone else struggling with this? Any potential workarounds?
I've also filed this as a feedback request (rdar://8620271) but figured I would ask here in the community forums as well.
The issue does not reproduce using the AVPlayerViewController which seems to indicate a problem with the AVPictureInPictureController on iOS 14 in general.
The issue also did not reproduce on beta 5, but started appearing on beta 6 -- probably a iOS 14 regression.
Some sample/pseudo code to illustrate the problem.
Code Block let player = AVPlayer(url: URL(string: "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4")!) let playerView = PlayerView() playerView.playerLayer.player = player let audioSession = AVAudioSession.sharedInstance() try? audioSession.setCategory(.playback) try? audioSession.setMode(.moviePlayback) try? audioSession.setActive(true) let pictureInPictureController = AVPictureInPictureController(playerLayer: playerView.playerLayer) @IBAction func playButtonTapped(_ sender: Any) { player.play() /* the video will not automatically pip when the app is entering the background */ } class PlayerView: UIView { override class var layerClass: AnyClass { return AVPlayerLayer.self } var playerLayer: AVPlayerLayer! { return layer as? AVPlayerLayer } }
Is anyone else struggling with this? Any potential workarounds?
I've also filed this as a feedback request (rdar://8620271) but figured I would ask here in the community forums as well.