国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > php开源 > 综合技术 > iOS-沙盒内视频导出到相册

iOS-沙盒内视频导出到相册

来源:程序员人生   发布时间:2016-09-06 15:25:14 阅读次数:3282次

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(@"视频保存成功."); } }
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生