使用AVPlayerViewController播放视频时遇到约束错误

时间:2018-10-15 06:53:12

标签: ios swift xcode

我正在使用以下代码:

override func viewDidLayoutSubviews() {
        UIApplication.shared.keyWindow?.addSubview(attachmentsView)
        attachmentsView.frame.size = CGSize(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
        attachmentsView.isHidden = true
    }


    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
            if((info[UIImagePickerControllerMediaType] as? String) == "public.movie" )
            {
                if let file = info[UIImagePickerControllerMediaURL] as? NSURL
                {


                    let av = AVPlayerViewController()
                    let player = AVPlayer(url: file as URL)
                    av.player = player
                    av.view.frame = attachmentsView.frame
                    av.modalPresentationStyle = UIModalPresentationStyle.fullScreen
                    self.addChildViewController(av)
                    attachmentsView.isHidden = false

                    attachmentsView.addSubview(av.view)
                    av.didMove(toParentViewController: self)

                }


            }
}

我遇到的错误:

enter image description here 我无法理解为什么出现此错误。请帮助我了解情况,并避免出现此错误。谢谢。

0 个答案:

没有答案