我在iOS上生成视频缩略图列表:
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
// get a reference to our storyboard cell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath as IndexPath)
cell.backgroundColor = UIColor.red
// Use the outlet in our custom class to get a reference to the UILabel in the cell
let imageView = UIImageView(frame: CGRect(x:0, y:0, width:cell.frame.size.width, height:cell.frame.size.height))
let image = uiImageArray[indexPath.row]
imageView.image = image
imageView.contentMode = UIViewContentMode.scaleAspectFit
cell.addSubview(imageView)
return cell
}
当用户点击图片我想播放视频时:
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
// handle tap events
print("You selected cell #\(indexPath.item)!")
self.assetToNav = indexPath.item
let data = self.assestArray[self.assetToNav]
self.playVideo(view: self, videoAsset: data)
}
func playVideo (view: UIViewController, videoAsset: PHAsset) {
guard (videoAsset.mediaType == .video) else {
print("Not a valid video media type")
return
}
PHCachingImageManager().requestAVAsset(forVideo: videoAsset, options: nil) { (asset, audioMix, args) in
let asset = asset as! AVURLAsset
DispatchQueue.main.async {
let player = AVPlayer(url: asset.url)
let playerViewController = VideoPlayerViewController()
playerViewController.player = player
view.present(playerViewController, animated: true) {
playerViewController.player!.play()
}
}
}
}
当视频开始播放时,我会在控制台错误中看到:
[framework] CUICatalog:提供的资产名称无效:'(null)'
我是初学者,快速编程,请帮忙