|
@@ -204,7 +204,10 @@
|
|
|
recordCtrl.songMessageArray = songNameArray;
|
|
|
recordCtrl.singleSongRecordMinutes = self.sourceModel.singleSongRecordMinutes;
|
|
|
[recordCtrl configTime:self.topView.duration recordFinishBlock:^(VIDEORECORDACTION action, NSMutableArray *videoArray) {
|
|
|
- [self uploadVideoWithVideoArray:videoArray songArray:songNameArray];
|
|
|
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+ [self uploadVideoWithVideoArray:videoArray songArray:songNameArray];
|
|
|
+ });
|
|
|
+
|
|
|
}];
|
|
|
recordCtrl.modalPresentationStyle = UIModalPresentationFullScreen;
|
|
|
[self presentViewController:recordCtrl animated:YES completion:nil];
|
|
@@ -216,37 +219,47 @@
|
|
|
}
|
|
|
|
|
|
- (void)uploadVideoWithVideoArray:(NSMutableArray *)videoArray songArray:(NSArray *)songArray {
|
|
|
- dispatch_main_async_safe(^{
|
|
|
- [MBProgressHUD ksShowHUDWithText:@"视频处理中..."];
|
|
|
- });
|
|
|
- NSMutableArray *urlArray = [NSMutableArray array];
|
|
|
- NSMutableArray *fileKeyArray = [NSMutableArray array];
|
|
|
- MJWeakSelf;
|
|
|
- for (NSInteger index = 0 ;index < videoArray.count; index++) {
|
|
|
+ [self outputVideoFileIndex:0 videoArray:videoArray songArray:songArray];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)outputVideoFileIndex:(NSInteger)index videoArray:(NSArray *)videoArray songArray:(NSArray *)songArray {
|
|
|
+ __block NSInteger fileIndex = index;
|
|
|
+ if (videoArray.count && videoArray.count > index) {
|
|
|
+ dispatch_main_async_safe(^{
|
|
|
+ [MBProgressHUD ksShowHUDWithText:@"视频处理中..."];
|
|
|
+ });
|
|
|
PHAsset *assset = videoArray[index];
|
|
|
+ MJWeakSelf;
|
|
|
[[TZImageManager manager] getVideoOutputPathWithAsset:assset presetName:AVAssetExportPresetMediumQuality success:^(NSString *outputPath) {
|
|
|
NSLog(@"视频导出到本地完成,沙盒路径为:%@",outputPath);
|
|
|
NSData *outputData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:outputPath]]; //压缩后的视频
|
|
|
NSLog(@"导出后的视频:%@",[NSString stringWithFormat:@"%.2fM",(CGFloat)outputData.length/(1024*1024)]);
|
|
|
- NSString *fileKey = [NSString stringWithFormat:@"%@%@", self.examRegistrationId, songArray[index]];
|
|
|
- [urlArray addObject:outputPath];
|
|
|
- [fileKeyArray addObject:fileKey];
|
|
|
- if (index == videoArray.count - 1) {
|
|
|
+ NSString *fileKey = [NSString stringWithFormat:@"%@%@", self.examRegistrationId, songArray[fileIndex]];
|
|
|
+ dispatch_main_async_safe(^{
|
|
|
[MBProgressHUD ksHideHUD];
|
|
|
- // 批量上传
|
|
|
- [weakSelf mutilUploadVideoWithUrl:urlArray fileKeyArray:fileKeyArray];
|
|
|
- }
|
|
|
-
|
|
|
+ fileIndex++;
|
|
|
+ // 上传
|
|
|
+ [weakSelf uploadVideoWithUrl:outputPath fileKey:fileKey videoArray:videoArray songArray:songArray fileIndex:fileIndex];
|
|
|
+ });
|
|
|
} failure:^(NSString *errorMessage, NSError *error) {
|
|
|
dispatch_main_async_safe(^{
|
|
|
[MBProgressHUD ksShowMessage:@"视频导出失败"];
|
|
|
- [MBProgressHUD ksHideHUD];
|
|
|
+ fileIndex++;
|
|
|
+ if (fileIndex == videoArray.count) {
|
|
|
+ [MBProgressHUD ksHideHUD];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+ // 继续导出
|
|
|
+ [self outputVideoFileIndex:fileIndex videoArray:videoArray songArray:songArray];
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|
|
|
}];
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+
|
|
|
- (void)deleteFileWithKey:(NSString *)fileKey {
|
|
|
NSDictionary *parm = UserDefault(fileKey);
|
|
|
NSString *localUrl = [parm stringValueForKey:@"localFileUrl"];
|
|
@@ -408,49 +421,7 @@
|
|
|
}
|
|
|
|
|
|
#pragma mark ------ 上传视频文件
|
|
|
-- (void)mutilUploadVideoWithUrl:(NSMutableArray *)videoUrlArray fileKeyArray:(NSMutableArray *)fileKeyArray {
|
|
|
- [self hudTipWillShow:YES];
|
|
|
- NSMutableArray *fileDataArray = [NSMutableArray array];
|
|
|
- for (NSString *videoUrl in videoUrlArray) {
|
|
|
- [fileDataArray addObject:[NSData dataWithContentsOfURL:[NSURL fileURLWithPath:videoUrl]]];
|
|
|
- }
|
|
|
- [KSRequestManager mutiVideoFileUpload:KS_POST fileDataArray:fileDataArray progress:^(int64_t bytesWritten, int64_t totalBytes) {
|
|
|
- dispatch_main_async_safe(^{
|
|
|
- // 显示进度
|
|
|
- if (self.HUD) {
|
|
|
- self.HUD.progress = bytesWritten / totalBytes;// progress是回调进度
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- } success:^(NSArray * _Nonnull dics) {
|
|
|
- [self hudTipWillShow:NO];
|
|
|
- for (NSInteger index = 0; index < dics.count; index++) {
|
|
|
- NSDictionary *dic = [dics objectAtIndex:index];
|
|
|
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
|
|
|
- NSString *fileUrl = [[dic dictionaryValueForKey:@"data"] stringValueForKey:@"url"];
|
|
|
- NSString *fileName = [[fileUrl componentsSeparatedByString:@"/"] lastObject];
|
|
|
- NSString *videoUrl = [fileDataArray objectAtIndex:index];
|
|
|
- NSString *fileKey = [fileKeyArray objectAtIndex:index];
|
|
|
- // 保存文件路径
|
|
|
- NSDictionary *parm = @{@"localFileUrl":videoUrl,
|
|
|
- @"remoteUrl":fileUrl,
|
|
|
- @"fileName": fileName};
|
|
|
- UserDefaultSet(parm, fileKey);
|
|
|
- [self.fileUrlArray addObject:fileUrl];
|
|
|
- [self checkSubmitButtonEnable];
|
|
|
- }
|
|
|
- else {
|
|
|
- [self MBPShow:MESSAGEKEY];
|
|
|
- }
|
|
|
- }
|
|
|
- [self.tableView reloadData];
|
|
|
-
|
|
|
- } faliure:^(NSError * _Nonnull error) {
|
|
|
- [self hudTipWillShow:NO];
|
|
|
- }];
|
|
|
-}
|
|
|
-
|
|
|
-- (void)uploadVideoWithUrl:(NSString *)videoUrl fileKey:(NSString *)fileKey {
|
|
|
+- (void)uploadVideoWithUrl:(NSString *)videoUrl fileKey:(NSString *)fileKey videoArray:(NSArray *)videoArray songArray:(NSArray *)songArray fileIndex:(NSInteger)fileIndex {
|
|
|
[self hudTipWillShow:YES];
|
|
|
|
|
|
NSData *fileData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:videoUrl]];
|
|
@@ -478,8 +449,8 @@
|
|
|
}
|
|
|
else {
|
|
|
[self MBPShow:MESSAGEKEY];
|
|
|
-
|
|
|
}
|
|
|
+ [self outputVideoFileIndex:fileIndex videoArray:videoArray songArray:songArray];
|
|
|
} faliure:^(NSError * _Nonnull error) {
|
|
|
[self hudTipWillShow:NO];
|
|
|
}];
|