频道栏目
首页 > 资讯 > IOS > 正文

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

16-06-28        来源:[db:作者]  
收藏   我要投稿

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(@"视频保存成功.");
    }
}
相关TAG标签
上一篇:漫谈android系统(6) 硬件抽象层kernel分析
下一篇:PhotoView 源码解读
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站