标签:
1.视频导出:
UIAlertController *av = [UIAlertController alertControllerWithTitle:@"提示" message:@"您确定要将视频导出到相册?" preferredStyle:UIAlertControllerStyleActionSheet];
[av addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//保存视频至相册(异步线程)
//videoSuccessI 记录上传成功的个数
videoSuccessI = 0;
//allVideos 取出沙盒内所有视频的视频名称
allVideos = [DataBaseTool videoFromDB];
[SVProgressHUD showWithStatus:@"正在导出,请耐心等待..."];
for (NSString *videoName in allVideos) {
//urlStr 沙盒内视频的完整路径
NSString *urlStr = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:videoName];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(urlStr)) {
//保存相册核心代码
UISaveVideoAtPathToSavedPhotosAlbum(urlStr, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
}
});
}
}]];
#pragma mark 视频保存完毕的回调
- (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInf{
if (error) {
[SVProgressHUD showErrorWithStatus:@"导出失败!"];
[SVProgressHUD dismiss];
NSLog(@"保存视频过程中发生错误,错误信息:%@",error.localizedDescription);
}else{
videoSuccessI++;
if (videoSuccessI == allVideos.count) {
[SVProgressHUD showSuccessWithStatus:@"视频导出成功,请在相册中查看!"];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[SVProgressHUD dismiss];
});
// UIAlertController *AV = [UIAlertController alertControllerWithTitle:nil message:@"视频导出成功,请在相册中查看!" preferredStyle:UIAlertControllerStyleAlert];
// [self presentViewController:AV animated:YES completion:nil];
}
NSLog(@"视频保存成功.");
}
}
标签:
原文地址:http://blog.csdn.net/qxuewei/article/details/51767163