ZLPhotoBrowser
ZLPhotoBrowser copied to clipboard
iColud视频问题,上传视频需要视频路径,但是确认回调中AVAsset无法得到该路径
感谢提交问题,提交 issue 前请先通过关键字搜索已经存在或解决了的 issue,避免重复提交相同内容。
由于框架内参数相对来说比较多,如果想要实现某种操作
- 请阅读README中相关功能介绍,查看是否有描述;
- 请翻阅下
ZLPhotoConfiguration类中所定义的属性,每个属性均有详细的注释;
- [ ] 我已经查阅了已有的issue,没有找到相同的
- [ ] 我想提出一个建议或bug,而不是问一个问题
关于 Issue
- 当前所使用的cocoapods版本
- 所遇到的问题(如有可能,请尽量详细描述,建议附上截图)
建议框架添加一个icould视频下载进度圈,只有下载完成才可以得到路径
+ (void)requestVideoForAsset:(PHAsset *)asset progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler completion:(void (^)(AVPlayerItem *item, NSDictionary *info))completion
{
PHVideoRequestOptions *option = [[PHVideoRequestOptions alloc] init];
option.networkAccessAllowed = YES;
option.progressHandler = ^(double progress, NSError *error, BOOL *stop, NSDictionary *info) {
//这里没有走
dispatch_async(dispatch_get_main_queue(), ^{
if (progressHandler) {
progressHandler(progress, error, stop, info);
}
});
};
[[PHCachingImageManager defaultManager] requestPlayerItemForVideo:asset options:option resultHandler:^(AVPlayerItem * _Nullable playerItem, NSDictionary * _Nullable info) {
if (completion) completion(playerItem, info);
}];
}
我试了下加载iCloud视频,貌似没有系统方法走 progress的回调
iCloud视频下载Photos框架有bug,可以如此解决: 1、添加extension。
extension PHAsset {
var isInCloud: Bool {
guard let resource = PHAssetResource.assetResources(for: self).first else {
return false
}
return !(resource.value(forKey: "locallyAvailable") as? Bool ?? true)
}
}
2、获取AVPlayerItem或者AVAsset时,用此方法:
@discardableResult
class func fetchVideo(for asset: PHAsset, progress: ( (CGFloat, Error?, UnsafeMutablePointer<ObjCBool>, [AnyHashable : Any]?) -> Void )? = nil, completion: @escaping ( (AVPlayerItem?, [AnyHashable: Any]?, Bool) -> Void )) -> PHImageRequestID {
let option = PHVideoRequestOptions()
option.isNetworkAccessAllowed = true
option.progressHandler = { (pro, error, stop, info) in
DispatchQueue.main.async {
progress?(CGFloat(pro), error, stop, info)
}
}
// iCloud视频,用此方法加载,否则加载不到原视频
if asset.isInCloud {
return PHImageManager.default().requestExportSession(forVideo: asset, options: option, exportPreset: AVAssetExportPresetHighestQuality, resultHandler: { (session, info) in
// iOS11 and earlier, callback is not on the main thread.
DispatchQueue.main.async {
let isDegraded = (info?[PHImageResultIsDegradedKey] as? Bool ?? false)
if let avAsset = session?.asset {
let item = AVPlayerItem(asset: avAsset)
completion(item, info, isDegraded)
}
}
})
} else {
return PHImageManager.default().requestPlayerItem(forVideo: asset, options: option) { (item, info) in
// iOS11 and earlier, callback is not on the main thread.
DispatchQueue.main.async {
let isDegraded = (info?[PHImageResultIsDegradedKey] as? Bool ?? false)
completion(item, info, isDegraded)
}
}
}
}
已添加进度条