警告:AVF上下文不适用于+ [MRAVOutputContext sharedAudioPresentationContext] _block_invoke Swift

时间:2019-03-27 04:41:28

标签: ios swift video youtube

嗨,我正尝试使用以下方法在收藏集视图单元中播放视频:Link

当我运行我的应用程序视频时,它会成功播放。 再次完成视频播放后,我们按下开始按钮,它崩溃了,并显示以下错误。

WF: _WebFilterIsActive returning: NO
  

警告:AVF上下文不适用于+ [MRAVOutputContext   sharedAudioPresentationContext] _block_invoke

我编写以下代码。

  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
            if collectionView == self.video_collectionview
            { 
                // For videoCollectionView
                let videocell = collectionView.dequeueReusableCell(withReuseIdentifier: "VideoCollectionViewCell", for: indexPath)as! VideoCollectionViewCell
                 videocell.videotitle.text = videotitle[indexPath.row]
                videocell.videotime.text = videotime[indexPath.row]
                let myVideoURL = videourls[indexPath.row]
                videocell.videoview.loadVideoURL(myVideoURL as URL)
               // videocell.videoview.layer.cornerRadius = 15

                return videocell
            }
        }

  func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        if collectionView == video_collectionview
         {  
            let videocell = collectionView.dequeueReusableCell(withReuseIdentifier: "VideoCollectionViewCell", for: indexPath)as! VideoCollectionViewCell
            let myVideoURL = videourls[indexPath.row]
            videocell.videoview.loadVideoURL(myVideoURL as URL)
        }
    }

1 个答案:

答案 0 :(得分:0)

需要安装XCDYouTubeKit pod文件。

在选择行方法中使用videoid参数调用了此函数。

func playVideo(videoid:String) {

        let playerViewController = AVPlayerViewController()
        self.present(playerViewController, animated: true, completion: nil)

        XCDYouTubeClient.default().getVideoWithIdentifier(videoid) { (video: XCDYouTubeVideo?, error: Error?) in
            if let streamURL = video?.streamURLs[XCDYouTubeVideoQuality.HD720.rawValue] {
                playerViewController.player = AVPlayer(url: streamURL)
                playerViewController.player?.play()
            } else {
                self.dismiss(animated: true, completion: nil)
            }
        }
    }