程序员人生 网站导航

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

栏目:综合技术时间:2016-09-06 15:25:14

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(@"视频保存成功."); } }
------分隔线----------------------------
------分隔线----------------------------

最新技术推荐