gpt4 book ai didi

ios - PHCacheImageManager.requestAVAsset(forVideo :. ..) 返回 nil AVAsset

转载 作者:搜寻专家 更新时间:2023-10-30 22:03:57 25 4
gpt4 key购买 nike

我正在使用 [PHCachingImageManager] 在 Collection View 中缓存视频。我可以显示使用缓存管理器生成的图像,但无法提取 AVAssets。

我尝试使用 .requestAVAsset(forVideo:...) 方法获取 AVAsset,但返回到结果处理程序的 [asset] 为零。尝试解开返回的 [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
})
}

我的委托(delegate)是可选的,但肯定有一些东西在里面,所以我相信它是引发错误的展开的 [asset]。

最佳答案

看起来我试图请求存储在 iCloud 中的视频 Assets ,但没有将视频请求选项设置为允许网络访问。

当从 PHCachingImageManager 请求视频时,我未能传递任何 PHVideoRequestOptions 对象。在请求 Assets 之前添加下面的行可以解决这个问题。

let options = PHVideoRequestOptions()
options.isNetworkAccessAllowed = true

我找到了 this thread在使用照片框架的开源图像选择器上。我正在测试的视频确实在 iCloud 中,这导致我返回的 Assets 为零。链接的线程还有一个很好的例子,可以在 objective-c 中连接一个进度处理程序:

options.networkAccessAllowed = YES;
options.progressHandler = ^(double progress, NSError *error, BOOL *stop, NSDictionary *info)
{
...
};

关于ios - PHCacheImageManager.requestAVAsset(forVideo :. ..) 返回 nil AVAsset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40446026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com