您好我正在尝试使用:Link播放集合视图单元格中的视频
当我运行我的应用程序视频成功播放。再次完成视频后,我们按下启动按钮就会崩溃。并显示以下错误。
WF: _WebFilterIsActive returning: NO
警告:+ [MRAVOutputContext sharedAudioPresentationContext] _block_invoke无法使用AVF上下文
我写下面的代码。
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)
}
}
需要安装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)
}
}
}