我正在使用[PHCachingImageManager]来缓存集合视图中的视频。我可以显示使用缓存管理器生成的图像,但是没有办法拉取AVAssets。
我尝试使用.requestAVAsset(forVideo:...) 方法获取AVAsset,但是传递给结果处理程序的[asset]为nil。尝试解包返回的[asset]时出现错误。
我还查看了返回给结果处理程序的[audioMix]和[info]参数,它们也为空。有人知道我在这里做错/遗漏了什么吗?
我尝试使用.requestAVAsset(forVideo:...) 方法获取AVAsset,但是传递给结果处理程序的[asset]为nil。尝试解包返回的[asset]时出现错误。
我还查看了返回给结果处理程序的[audioMix]和[info]参数,它们也为空。有人知道我在这里做错/遗漏了什么吗?
viewDidLoad() {
let videosAlbum = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .smartAlbumVideos, options: nil)
self.videoAssets = PHAsset.fetchAssets(in: videosAlbum.object(at: 0), options: nil)
self.imgCacheManager.startCachingImages(for: self.videoAssets.objects(at: [0, videoAssets.count-1]), targetSize: CGSize(width: 150, height: 150), contentMode: .aspectFit, options: nil)
}
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let selectedAsset = self.imgCacheManager.requestAVAsset(forVideo: self.videoAssets.object(at: indexPath.item), options: nil, resultHandler: {
asset,_,_ in
self.delegate.selectedVideo(Asset: asset!) // this is the line I get the error
})
}
我的代理是可选的,但肯定有一些内容,所以我很自信它是未解包的[asset]引发了错误。
options.isNetworkAccessAllowed = true
帮了我很多。 - olha