PHAsset类的对象对应的视频并不一定保存在本地相册,也可能保存在云相册,本地只是有一个缩略图,需要联网同步:
// 允许同步网络相册
PHVideoRequestOptions *option = [[PHVideoRequestOptions alloc] init];
option.networkAccessAllowed = YES;
option.progressHandler = ^(double progress, NSError *error, BOOL *stop, NSDictionary *info) {
if (error) {
weakSelf.progressView.hidden = YES;
weakSelf.videoImageView.image = preImage;
[SVProgressHUD showErrorWithStatus:@"相册同步资源失败"];
}
};
// 获取视频数据
[[PHImageManager defaultManager] requestAVAssetForVideo:videoAsset options:option resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
if ([asset isKindOfClass:[AVURLAsset class]]) {
AVURLAsset* urlAsset = (AVURLAsset*)asset;
NSNumber *size;
[urlAsset.URL getResourceValue:&size forKey:NSURLFileSizeKey error:nil];
// 视频大小
CGFloat videoSize = [size floatValue]/(1024.0*1024.0);
if (videoSize > 12.00) {
weakSelf.progressView.hidden = YES;
weakSelf.videoImageView.image = preImage;
[SVProgressHUD showErrorWithStatus:@"上传视频不能大于12M"];
} else {
// 视频数据
NSData *data = [NSData dataWithContentsOfURL:urlAsset.URL];
[[JKRQiNiuManager sharedManager] uploadVideo:data progressHandler:^(NSString *key, float percent) {
NSLog(@"%@-%f", key, percent);
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.progressView.progress = percent;
});
} success:^(NSString * _Nonnull url) {
weakSelf.progressView.hidden = YES;
} failure:^{
weakSelf.progressView.hidden = YES;
weakSelf.videoImageView.image = preImage;
[SVProgressHUD showErrorWithStatus:@"上传视频失败"];
}];
}
}
}];
七牛上传
QNUploadOption *uploadOption = [[QNUploadOption alloc] initWithMime:nil progressHandler:^(NSString *key, float percent) {
progress(key, percent);
} params:nil checkCrc:NO cancellationSignal:^BOOL{
return self.flag;
}];
[self.qnUploadManager putData:video key:@"filename" token:@"token" complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
if (info.ok) {
NSString *vidoURL = @"";
success(vidoURL);
} else {
failure();
}
} option:uploadOption];
网友评论