CUICatalog: Invalid asset name: '(null)' when playing video

I create a list of video files in 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 } 

When the user clicks the image, I want to play the video:

  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() } } } } 

When the videos start playing, I see an error in the console:

[framework] CUICatalog: Invalid asset name: '(null)'

I'm starting to program fast, help

+5
source share

Source: https://habr.com/ru/post/1272410/


All Articles