I'm using AVPlayerViewController to play a local video inline.
My desired behavior is that videos playing in a PIP window will close automatically when the video ends.
Is there a way to do this with AVPlayerViewController?
My desired behavior is that videos playing in a PIP window will close automatically when the video ends.
Is there a way to do this with AVPlayerViewController?
Code Block swift import UIKit import AVKit class ViewController: UIViewController { var playerViewController = AVPlayerViewController() var videoPath = "video.mov" override func viewDidLoad() { super.viewDidLoad() do { try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback) } catch { } let player = AVPlayer(url: URL(fileURLWithPath: videoPath)) playerViewController.player = player NotificationCenter.default.addObserver( self, selector: #selector(playerDidFinishPlaying), name: .AVPlayerItemDidPlayToEndTime, object: player.currentItem ) playerViewController.showsPlaybackControls = true playerViewController.entersFullScreenWhenPlaybackBegins = true self.addChild(playerViewController) self.view.addSubview(playerViewController.view) } @objc func playerDidFinishPlaying(note: NSNotification) { // ??? } }