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(@"視頻保存成功.");
}
}
下一篇 更換git默認沖突編輯器的方法