我有一个ViewController(例如MyVC.swift),它通过AVPlayerViewController
方法中的给定URL创建viewDidAppear
并播放它。
通过单击某些按钮,应用程序重定向到此屏幕,并且我尚未在MyVC.swift上添加任何观察者。
当用户确实快速打开和关闭此屏幕时,应用崩溃 消息
-[NSKeyValueObservance保留]:消息发送到已释放实例0x13b092f40
func loadPlayer(){
guard let url = URL(string: video_url) else {return}
playerController = AVPlayerViewController()
guard let playerVC = playerController else{return}
playerVC.showsPlaybackControls = true
playerVC.player = AVPlayer(url:url)
playerVC.player?.play()
DispatchQueue.main.async {
self.addChildViewController(playerVC)
self.contentView.addSubview(playerVC.view)
playerVC.view.frame = self.contentView.bounds
playerVC.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
}
}