|
@@ -11,8 +11,18 @@
|
|
|
#import "RecordListCell.h"
|
|
|
#import "RecordBottomView.h"
|
|
|
#import "RecordTipsView.h"
|
|
|
+#import "RecordExamModel.h"
|
|
|
+#import "KSMediaManager.h"
|
|
|
+#import "WMPlayer.h"
|
|
|
|
|
|
-@interface RecordExamViewController ()<UITableViewDelegate, UITableViewDataSource>
|
|
|
+@interface RecordExamViewController ()<UITableViewDelegate, UITableViewDataSource,WMPlayerDelegate>
|
|
|
+{
|
|
|
+ WMPlayer *_wmPlayer;
|
|
|
+ CGRect _playerFrame;
|
|
|
+}
|
|
|
+@property (nonatomic, assign) BOOL isRatation;
|
|
|
+
|
|
|
+@property (nonatomic, strong) UIView *bgView;
|
|
|
|
|
|
@property (nonatomic, strong) RecordBodyView *topView;
|
|
|
|
|
@@ -22,6 +32,16 @@
|
|
|
|
|
|
@property (nonatomic, strong) RecordBottomView *bottomView;
|
|
|
|
|
|
+@property (nonatomic, strong) RecordExamModel *sourceModel;
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSMutableArray *songArray;
|
|
|
+
|
|
|
+@property (nonatomic, strong) KSMediaManager *mediaManager;
|
|
|
+
|
|
|
+@property (strong, nonatomic) MBProgressHUD *HUD;
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSMutableArray *fileUrlArray;
|
|
|
+
|
|
|
@end
|
|
|
|
|
|
@implementation RecordExamViewController
|
|
@@ -31,6 +51,7 @@
|
|
|
// Do any additional setup after loading the view.
|
|
|
self.ks_prefersNavigationBarHidden = YES;
|
|
|
[self configUI];
|
|
|
+ [self requestData];
|
|
|
}
|
|
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
@@ -46,6 +67,29 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+- (void)requestData {
|
|
|
+ [self showhud];
|
|
|
+ [KSRequestManager stuRecordDetailRequest:KS_GET examRegistrationId:self.examRegistrationId success:^(NSDictionary * _Nonnull dic) {
|
|
|
+ [self removehub];
|
|
|
+ if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
|
|
|
+ self.sourceModel = [[RecordExamModel alloc] initWithDictionary:[dic dictionaryValueForKey:@"data"]];
|
|
|
+ [self evaluateSource];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [self MBPShow:MESSAGEKEY];
|
|
|
+ }
|
|
|
+ } faliure:^(NSError * _Nonnull error) {
|
|
|
+ [self removehub];
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)evaluateSource {
|
|
|
+ [self.topView configTime:[NSString stringWithFormat:@"%.0f", self.sourceModel.subTime]];
|
|
|
+ [self.tipsView configWithEndTime:self.sourceModel.actualExamEndTime];
|
|
|
+ self.songArray = [NSMutableArray arrayWithArray:self.sourceModel.songJson];
|
|
|
+ [self.tableView reloadData];
|
|
|
+}
|
|
|
+
|
|
|
- (void)configUI {
|
|
|
|
|
|
[self.view addSubview:self.topView];
|
|
@@ -71,15 +115,65 @@
|
|
|
|
|
|
#pragma mark ----- table data source
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
|
-// return self.dataArray.count;
|
|
|
+// return self.songArray.count;
|
|
|
return 3;
|
|
|
}
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ SongJson *model = self.songArray[indexPath.row];
|
|
|
RecordListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RecordListCell"];
|
|
|
+ MJWeakSelf;
|
|
|
+ [cell configCellWithSource:model examRegistrationId:self.examRegistrationId operationCallback:^(RECORDTYPE type, NSString *fileKey) {
|
|
|
+ [weakSelf opreationCellType:type fileKey:fileKey];
|
|
|
+ }];
|
|
|
return cell;
|
|
|
}
|
|
|
|
|
|
+- (void)opreationCellType:(RECORDTYPE)type fileKey:(NSString *)fileKey {
|
|
|
+ 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];
|
|
|
+ }];
|
|
|
+ [self.mediaManager takePhoto];
|
|
|
+ }
|
|
|
+ else { // 删除
|
|
|
+ [self deleteFileWithKey:fileKey];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)deleteFileWithKey:(NSString *)fileKey {
|
|
|
+ NSDictionary *parm = UserDefault(fileKey);
|
|
|
+ NSString *localUrl = [parm stringValueForKey:@"localFileUrl"];
|
|
|
+ [self removeVideoWithPath:localUrl];
|
|
|
+ UserDefaultRemoveObjectForKey(fileKey);
|
|
|
+ [self.tableView reloadData];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ RecordListCell *cell = [tableView cellForRowAtIndexPath:indexPath];
|
|
|
+ if (cell.fileMessage) {
|
|
|
+ // 播放
|
|
|
+ NSString *localUrl = [cell.fileMessage stringValueForKey:@"localFileUrl"];
|
|
|
+ if ([[NSFileManager defaultManager] fileExistsAtPath:localUrl]) {
|
|
|
+ [self playVideoWithUrl:[NSURL fileURLWithPath:localUrl]];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ NSString *remoteUrl = [cell.fileMessage stringValueForKey:@"remoteUrl"];
|
|
|
+ [self playVideoWithUrl:[NSURL URLWithString:remoteUrl]];
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
#pragma mark --- lazying
|
|
|
- (RecordBodyView *)topView {
|
|
|
if (!_topView) {
|
|
@@ -99,7 +193,9 @@
|
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
|
}
|
|
|
else { // 时间结束
|
|
|
-
|
|
|
+ self.bottomView.finishButton.userInteractionEnabled = NO;
|
|
|
+ [self.bottomView.finishButton setTitle:@"考试已结束" forState:UIControlStateNormal];
|
|
|
+ [self.bottomView.finishButton setBackgroundColor:HexRGB(0xcccccc)];
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -112,7 +208,6 @@
|
|
|
|
|
|
- (UITableView *)tableView {
|
|
|
if (!_tableView) {
|
|
|
-// CGFloat yPosition = kScreenWidth / 207 * 79 + 11;
|
|
|
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
|
|
|
_tableView.delegate = self;
|
|
|
_tableView.dataSource = self;
|
|
@@ -143,8 +238,134 @@
|
|
|
|
|
|
- (void)submitAction {
|
|
|
// 提交 完成考试
|
|
|
+ NSString *videoUrl = @"";
|
|
|
+ [KSRequestManager stuEndRecordFinishRequest:KS_POST examRegistrationId:self.examRegistrationId videoUrl:videoUrl success:^(NSDictionary * _Nonnull dic) {
|
|
|
+
|
|
|
+ } faliure:^(NSError * _Nonnull error) {
|
|
|
+
|
|
|
+ }];
|
|
|
}
|
|
|
|
|
|
+#pragma mark ------ 上传视频文件
|
|
|
+
|
|
|
+- (void)uploadVideoWithUrl:(NSString *)videoUrl fileKey:(NSString *)fileKey {
|
|
|
+ [self hudTipWillShow:YES];
|
|
|
+
|
|
|
+ NSData *fileData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:videoUrl]];
|
|
|
+ [KSRequestManager videoFileUpload:KS_POST fileData:fileData progress:^(int64_t bytesWritten, int64_t totalBytes) {
|
|
|
+ dispatch_main_async_safe(^{
|
|
|
+ // 显示进度
|
|
|
+ if (self.HUD) {
|
|
|
+ self.HUD.progress = bytesWritten / totalBytes;// progress是回调进度
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } success:^(NSDictionary * _Nonnull dic) {
|
|
|
+ [self hudTipWillShow:NO];
|
|
|
+ if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
|
|
|
+ NSString *fileUrl = [[dic dictionaryValueForKey:@"data"] stringValueForKey:@"url"];
|
|
|
+
|
|
|
+ // 保存文件路径
|
|
|
+ NSDictionary *parm = @{@"localFileUrl":videoUrl,@"remoteUrl":fileUrl};
|
|
|
+ UserDefaultSet(parm, fileKey);
|
|
|
+ [self.tableView reloadData];
|
|
|
+
|
|
|
+ [self.fileUrlArray addObject:fileUrl];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [self MBPShow:MESSAGEKEY];
|
|
|
+
|
|
|
+ }
|
|
|
+ } faliure:^(NSError * _Nonnull error) {
|
|
|
+ [self hudTipWillShow:NO];
|
|
|
+ }];
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+- (void)removeVideoWithPath:(NSString *)videoUrl {
|
|
|
+ NSFileManager *fileMamager = [NSFileManager defaultManager];
|
|
|
+ if ([fileMamager fileExistsAtPath:videoUrl]) {
|
|
|
+ [fileMamager removeItemAtPath:videoUrl error:nil];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)hudTipWillShow:(BOOL)willShow{
|
|
|
+ if (willShow) {
|
|
|
+ [self resignFirstResponder];
|
|
|
+ UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
|
|
|
+ if (!_HUD) {
|
|
|
+ _HUD = [MBProgressHUD showHUDAddedTo:keyWindow animated:YES];
|
|
|
+ _HUD.mode = MBProgressHUDModeDeterminateHorizontalBar;
|
|
|
+ _HUD.label.text = @"正在转码视频...";
|
|
|
+ _HUD.removeFromSuperViewOnHide = YES;
|
|
|
+ }else{
|
|
|
+ _HUD.progress = 0;
|
|
|
+ [keyWindow addSubview:_HUD];
|
|
|
+ [_HUD showAnimated:YES];
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ [_HUD hideAnimated:YES];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+- (NSMutableArray *)fileUrlArray {
|
|
|
+ if (!_fileUrlArray) {
|
|
|
+ _fileUrlArray = [NSMutableArray arrayWithCapacity:self.songArray.count];
|
|
|
+ }
|
|
|
+ return _fileUrlArray;
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark ------- 播放文件
|
|
|
+- (void)playVideoWithUrl:(NSURL *)fileUrl {
|
|
|
+ _playerFrame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
|
|
|
+ _wmPlayer = [[WMPlayer alloc] initWithFrame:_playerFrame];
|
|
|
+ WMPlayerModel *playModel = [[WMPlayerModel alloc] init];
|
|
|
+ playModel.videoURL = fileUrl;
|
|
|
+ _wmPlayer.playerModel = playModel;
|
|
|
+ _wmPlayer.delegate = self;
|
|
|
+ _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
|
|
|
+ _bgView.backgroundColor = [UIColor blackColor];
|
|
|
+ [[UIApplication sharedApplication].keyWindow addSubview:_bgView];
|
|
|
+ [[UIApplication sharedApplication].keyWindow addSubview:_wmPlayer];
|
|
|
+ [[UIApplication sharedApplication].keyWindow bringSubviewToFront:_wmPlayer];
|
|
|
+
|
|
|
+ [_wmPlayer play];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)wmplayer:(WMPlayer *)wmplayer clickedCloseButton:(UIButton *)backBtn {
|
|
|
+ [wmplayer removePlayer];
|
|
|
+ [_bgView removeFromSuperview];
|
|
|
+ [self setNeedsStatusBarAppearanceUpdate];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)wmplayer:(WMPlayer *)wmplayer clickedFullScreenButton:(UIButton *)fullScreenBtn {
|
|
|
+ self.isRatation = !self.isRatation;
|
|
|
+
|
|
|
+ if (self.isRatation) {
|
|
|
+ [wmplayer removeFromSuperview];
|
|
|
+ [UIView animateWithDuration:1.0f animations:^{
|
|
|
+ wmplayer.transform = CGAffineTransformMakeRotation(M_PI_2);
|
|
|
+
|
|
|
+ } completion:^(BOOL finished) {
|
|
|
+ wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
|
|
|
+ [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
|
|
|
+ [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [wmplayer removeFromSuperview];
|
|
|
+
|
|
|
+ [UIView animateWithDuration:1.0f animations:^{
|
|
|
+ // 复原
|
|
|
+ wmplayer.transform = CGAffineTransformIdentity;
|
|
|
+
|
|
|
+ } completion:^(BOOL finished) {
|
|
|
+ wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
|
|
|
+ [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
|
|
|
+ [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
|
|
|
+ }];
|
|
|
+ }
|
|
|
+}
|
|
|
/*
|
|
|
#pragma mark - Navigation
|
|
|
|