|
@@ -11,11 +11,12 @@
|
|
|
#import "RecordListCell.h"
|
|
|
#import "RecordBottomView.h"
|
|
|
#import "RecordTipsView.h"
|
|
|
-#import "KSMediaManager.h"
|
|
|
#import "WMPlayer.h"
|
|
|
#import "SongModel.h"
|
|
|
#import "KSGuideMaskView.h"
|
|
|
#import "KSNormalAlertView.h"
|
|
|
+#import "KSVideoRecordViewController.h"
|
|
|
+#import "TZImageManager.h"
|
|
|
|
|
|
@interface RecordExamViewController ()<UITableViewDelegate, UITableViewDataSource,WMPlayerDelegate>
|
|
|
{
|
|
@@ -36,8 +37,6 @@
|
|
|
|
|
|
@property (nonatomic, strong) NSMutableArray *songArray;
|
|
|
|
|
|
-@property (nonatomic, strong) KSMediaManager *mediaManager;
|
|
|
-
|
|
|
@property (strong, nonatomic) MBProgressHUD *HUD;
|
|
|
|
|
|
@property (nonatomic, strong) NSMutableArray *fileUrlArray;
|
|
@@ -179,31 +178,75 @@
|
|
|
RecordListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RecordListCell"];
|
|
|
MJWeakSelf;
|
|
|
[cell configCellWithSource:model examRegistrationId:self.examRegistrationId operationCallback:^(RECORDTYPE type, NSString *fileKey) {
|
|
|
- [weakSelf opreationCellType:type fileKey:fileKey];
|
|
|
+ [weakSelf opreationCellType:type fileKey:fileKey index:indexPath.row];
|
|
|
}];
|
|
|
return cell;
|
|
|
}
|
|
|
|
|
|
-- (void)opreationCellType:(RECORDTYPE)type fileKey:(NSString *)fileKey {
|
|
|
+- (void)opreationCellType:(RECORDTYPE)type fileKey:(NSString *)fileKey index:(NSInteger)cellIndex {
|
|
|
if (type == RECORDTYPE_RECORD) { // 录像
|
|
|
- self.mediaManager = [[KSMediaManager alloc] init];
|
|
|
- self.mediaManager.mediaType = MEDIATYPE_VIDEO;
|
|
|
- self.mediaManager.maxPhotoNumber = 1;
|
|
|
- self.mediaManager.baseCtrl = self;
|
|
|
- self.mediaManager.maxDuration = self.sourceModel.singleSongRecordMinutes * 60;
|
|
|
- MJWeakSelf;
|
|
|
- [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
|
|
|
- NSLog(@"%@", videoUrl);
|
|
|
- // 上传视频
|
|
|
- [weakSelf uploadVideoWithUrl:videoUrl fileKey:fileKey];
|
|
|
+ NSMutableArray *songNameArray = [NSMutableArray array];
|
|
|
+ for (NSInteger i = 0; i < self.songArray.count; i++) {
|
|
|
+ if (i >= cellIndex) {
|
|
|
+ // 从选择的开始->后面未录制的添加到待录制里
|
|
|
+ SongModel *model = self.songArray[i];
|
|
|
+ NSString *fileKey = [NSString stringWithFormat:@"%@%@", self.examRegistrationId, model.songName];
|
|
|
+ NSDictionary *fileMessage = UserDefault(fileKey);
|
|
|
+ if (fileMessage == nil) {
|
|
|
+ [songNameArray addObject:model.songName];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ KSVideoRecordViewController *recordCtrl = [[KSVideoRecordViewController alloc] init];
|
|
|
+ recordCtrl.subjectName = self.subjectName;
|
|
|
+ recordCtrl.leverName = self.leverName;
|
|
|
+ recordCtrl.songMessageArray = songNameArray;
|
|
|
+ recordCtrl.singleSongRecordMinutes = self.sourceModel.singleSongRecordMinutes;
|
|
|
+ [recordCtrl configTime:self.topView.duration recordFinishBlock:^(VIDEORECORDACTION action, NSMutableArray *videoArray) {
|
|
|
+ [self uploadVideoWithVideoArray:videoArray songArray:songNameArray];
|
|
|
}];
|
|
|
- [self.mediaManager takePhoto];
|
|
|
+ recordCtrl.modalPresentationStyle = UIModalPresentationFullScreen;
|
|
|
+ [self presentViewController:recordCtrl animated:YES completion:nil];
|
|
|
+
|
|
|
}
|
|
|
else { // 删除
|
|
|
[self deleteFileWithKey:fileKey];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+- (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++) {
|
|
|
+ PHAsset *assset = videoArray[index];
|
|
|
+ [[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) {
|
|
|
+ [MBProgressHUD ksHideHUD];
|
|
|
+ // 批量上传
|
|
|
+ [weakSelf mutilUploadVideoWithUrl:urlArray fileKeyArray:fileKeyArray];
|
|
|
+ }
|
|
|
+
|
|
|
+ } failure:^(NSString *errorMessage, NSError *error) {
|
|
|
+ dispatch_main_async_safe(^{
|
|
|
+ [MBProgressHUD ksShowMessage:@"视频导出失败"];
|
|
|
+ [MBProgressHUD ksHideHUD];
|
|
|
+ });
|
|
|
+ }];
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
- (void)deleteFileWithKey:(NSString *)fileKey {
|
|
|
NSDictionary *parm = UserDefault(fileKey);
|
|
|
NSString *localUrl = [parm stringValueForKey:@"localFileUrl"];
|
|
@@ -365,6 +408,47 @@
|
|
|
}
|
|
|
|
|
|
#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 {
|
|
|
[self hudTipWillShow:YES];
|