MusicRoomDetailViewController.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. //
  2. // MusicRoomDetailViewController.m
  3. // KulexiuForStudent
  4. //
  5. // Created by 王智 on 2022/6/27.
  6. //
  7. #import "MusicRoomDetailViewController.h"
  8. #import "AccompanyArrangeCell.h"
  9. #import "AccompanyHomeworkCell.h"
  10. #import "AccompanyRemarkCell.h"
  11. #import "AccompanyDetailBottomView.h"
  12. #import "HomeworkDetailModel.h"
  13. #import "EvaluateDetailModel.h"
  14. #import "KSChatConversationViewController.h"
  15. #import "KSGroupConversationController.h"
  16. #import <WMPlayer.h>
  17. #import <RecordCheckManager.h>
  18. #import "KSPremissionAlert.h"
  19. #import "KSMediaManager.h"
  20. #import "OnlineClassManager.h"
  21. #import "MusicRoomCourseInfoCell.h"
  22. #import "CourseGroupNavView.h"
  23. #import "HomeworkSubmitAlertView.h"
  24. @interface MusicRoomDetailViewController ()<UITableViewDelegate,UITableViewDataSource,WMPlayerDelegate>
  25. {
  26. WMPlayer *_wmPlayer;
  27. CGRect _playerFrame;
  28. }
  29. @property (nonatomic, strong) CourseGroupNavView *navView;
  30. @property (nonatomic, strong) UIView *bgView;
  31. @property (nonatomic, assign) BOOL isRatation;
  32. @property (nonatomic, strong) UITableView *tableView;
  33. @property (nonatomic, strong) NSMutableArray *fileArray;
  34. @property (nonatomic, strong) KSMediaManager *mediaManager;
  35. @property (nonatomic, strong) HomeworkDetailModel *homeworkModel;
  36. @property (nonatomic, strong) AccompanyDetailBottomView *bottomView;
  37. @property (nonatomic, strong) OnlineClassManager *classManager;
  38. @property (nonatomic, assign) BOOL canModify;
  39. @property (nonatomic, assign) BOOL isModify; // 是否修改作业
  40. @property (nonatomic, strong) HomeworkSubmitAlertView *submitAlertView;
  41. @end
  42. @implementation MusicRoomDetailViewController
  43. - (void)viewDidLoad {
  44. [super viewDidLoad];
  45. // Do any additional setup after loading the view.
  46. self.ks_prefersNavigationBarHidden = YES;
  47. [self configUI];
  48. self.isModify = NO;
  49. }
  50. - (void)viewWillAppear:(BOOL)animated {
  51. [super viewWillAppear:animated];
  52. [self requestCourseInfoMessage];
  53. }
  54. - (void)requestCourseInfoMessage {
  55. [self requestHomeworkMessage];
  56. [self requestRoomConfig];
  57. }
  58. - (void)requestRoomConfig {
  59. [KSNetworkingManager selectRoomConfigRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  60. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  61. NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
  62. if (self.courseType == MUTIL_COURSE_TYPE_GROUP) {
  63. self.joinRoomBeforeTime = [result ks_integerValueForKey:@"groupStartTime"];
  64. self.quitRomeEndTime = [result ks_integerValueForKey:@"groupEndTime"];
  65. }
  66. else {
  67. self.joinRoomBeforeTime = [result ks_integerValueForKey:@"pianoStartTime"];
  68. self.quitRomeEndTime = [result ks_integerValueForKey:@"pianoEndTime"];
  69. }
  70. }
  71. else {
  72. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  73. }
  74. } faliure:^(NSError * _Nonnull error) {
  75. }];
  76. }
  77. - (void)requestHomeworkMessage {
  78. [KSNetworkingManager homeworkDetailRequest:KS_GET courseId:self.courseId success:^(NSDictionary * _Nonnull dic) {
  79. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  80. self.homeworkModel = [[HomeworkDetailModel alloc] initWithDictionary:[dic ks_dictionaryValueForKey:@"data"]];
  81. if (self.homeworkModel.submitHomework == 1) {
  82. if (![NSString isEmptyString:self.homeworkModel.studentAttachments]) {
  83. self.fileArray = [NSMutableArray arrayWithArray:[self.homeworkModel.studentAttachments componentsSeparatedByString:@","]];
  84. }
  85. else {
  86. self.fileArray = [NSMutableArray array];
  87. }
  88. }
  89. else {
  90. self.fileArray = [NSMutableArray array];
  91. }
  92. }
  93. else {
  94. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  95. }
  96. [self evaluateViewDisplay];
  97. [self.tableView reloadData];
  98. } faliure:^(NSError * _Nonnull error) {
  99. }];
  100. }
  101. - (void)evaluateViewDisplay {
  102. // 老师布置过作业且没有点评 可以点击
  103. if (self.homeworkModel.reviewHomework == 1 || self.homeworkModel.decorateHomework == 0) {
  104. self.canModify = NO;
  105. }
  106. else {
  107. self.canModify = YES;
  108. }
  109. if ([self.homeworkModel.courseStatus isEqualToString:@"COMPLETE"]) {
  110. self.bottomView.hidden = YES;
  111. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, 15)];
  112. self.tableView.tableFooterView = bottomView;
  113. }
  114. else {
  115. CGFloat bottomHeight = [AccompanyDetailBottomView getViewHeight];
  116. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, bottomHeight)];
  117. self.tableView.tableFooterView = bottomView;
  118. self.bottomView.hidden = NO;
  119. self.bottomView.actionButton.userInteractionEnabled = YES;
  120. [self.bottomView.actionButton setTitle:@"进入教室" forState:UIControlStateNormal];
  121. [self.bottomView.actionButton setBackgroundColor:THEMECOLOR];
  122. [self.bottomView.actionButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  123. }
  124. }
  125. - (void)configUI {
  126. [self.scrollView removeFromSuperview];
  127. UIImage *bgImage = [UIImage imageNamed:@"homework_detail_bg"];
  128. CGFloat height = bgImage.size.height / bgImage.size.width * KPortraitWidth;
  129. UIImageView *imageView = [[UIImageView alloc] initWithImage:bgImage];
  130. imageView.frame = CGRectMake(0, 0, KPortraitWidth, height);
  131. [self.view addSubview:imageView];
  132. [self.view addSubview:self.navView];
  133. CGFloat navHeight = [CourseGroupNavView getViewHeight];
  134. [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
  135. make.left.right.top.mas_equalTo(self.view);
  136. make.height.mas_equalTo(navHeight);
  137. }];
  138. [self.view addSubview:self.tableView];
  139. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  140. make.left.right.mas_equalTo(self.view);
  141. make.top.mas_equalTo(self.navView.mas_bottom);
  142. make.bottom.mas_equalTo(self.view.mas_bottom);
  143. }];
  144. CGFloat bottomHeight = [AccompanyDetailBottomView getViewHeight];
  145. [self.view addSubview:self.bottomView];
  146. [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  147. make.left.right.bottom.mas_equalTo(self.view);
  148. make.height.mas_equalTo(bottomHeight);
  149. }];
  150. self.bottomView.hidden = YES;
  151. }
  152. #pragma mark --- table data source
  153. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  154. return 4;
  155. }
  156. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  157. if (indexPath.row == 0) {
  158. MusicRoomCourseInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MusicRoomCourseInfoCell"];
  159. BOOL isGroup = self.courseType == MUTIL_COURSE_TYPE_GROUP ? YES : NO;
  160. MJWeakSelf;
  161. [cell configWithSource:self.homeworkModel isGroup:isGroup chatAction:^(NSString * _Nonnull targetId) {
  162. [weakSelf chatAction:targetId];
  163. }];
  164. return cell;
  165. }
  166. else if (indexPath.row == 1) {
  167. AccompanyArrangeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyArrangeCell"];
  168. BOOL hasArrange = self.homeworkModel.decorateHomework == 1 ? YES : NO;
  169. [cell configWithHomeworkContent:self.homeworkModel.content hasArrangeHomework:hasArrange];
  170. return cell;
  171. }
  172. else if (indexPath.row == 2) {
  173. // studentAttachments
  174. BOOL canDisplay = self.homeworkModel.decorateHomework == 1 ? YES : NO;
  175. BOOL isExpired = self.homeworkModel.homeworkExpire == 1 ? YES : NO;
  176. AccompanyHomeworkCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyHomeworkCell"];
  177. cell.canSubmit = NO;
  178. cell.showSubmitButton = self.canModify;
  179. MJWeakSelf;
  180. [cell configWithAttachmentArray:self.fileArray canDisplaySubmitView:canDisplay isExpired:isExpired callback:^(HOMEWORKACTION action, NSInteger viewIndex) {
  181. [weakSelf operationActionWithType:action index:viewIndex];
  182. }];
  183. return cell;
  184. }
  185. else {
  186. AccompanyRemarkCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyRemarkCell"];
  187. BOOL hasEvaluate = self.homeworkModel.reviewHomework == 1? YES : NO;
  188. BOOL hasSubmitHomework = self.homeworkModel.submitHomework == 1 ? YES : NO;
  189. [cell configWithRemarkMessage:self.homeworkModel.teacherReplied hasEvaluate:hasEvaluate hasSubmitHomework:hasSubmitHomework];
  190. return cell;
  191. }
  192. }
  193. - (void)chatAction:(NSString *)targetId {
  194. if ([NSString isEmptyString:targetId]) {
  195. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"报名未结束,暂无群组"];
  196. return;
  197. }
  198. TUIChatConversationModel *model = [[TUIChatConversationModel alloc] init];
  199. model.groupID = targetId;
  200. KSGroupConversationController *ctrl = [[KSGroupConversationController alloc] init];
  201. ctrl.conversation = model;
  202. [self.navigationController pushViewController:ctrl animated:YES];
  203. }
  204. - (void)operationActionWithType:(HOMEWORKACTION)action index:(NSInteger)viewIndex {
  205. switch (action) {
  206. case HOMEWORKACTION_PLAY:
  207. {
  208. [self playVideoIndex:viewIndex];
  209. }
  210. break;
  211. case HOMEWORKACTION_DELETE:
  212. {
  213. [self deleteVideoIndex:viewIndex];
  214. }
  215. break;
  216. case HOMEWORKACTION_HOMEWOEKPAGE:
  217. {
  218. if (!_submitAlertView) {
  219. [self.submitAlertView configWithFileArray:self.fileArray];
  220. }
  221. else {
  222. [self.submitAlertView configWithFileArray:self.submitAlertView.sourceArray];
  223. }
  224. [self.submitAlertView showInView:self.view];
  225. }
  226. default:
  227. break;
  228. }
  229. }
  230. #pragma mark --- 上传视频文件
  231. - (void)uploadVideoWithUrl:(NSString *)videoUrl {
  232. NSURL *uploadFileUrl = [NSURL fileURLWithPath:videoUrl];
  233. NSData *fileData = [NSData dataWithContentsOfURL:uploadFileUrl];
  234. NSString *suffix = [NSString stringWithFormat:@".%@",[uploadFileUrl pathExtension]];
  235. [UPLOAD_MANAGER configWithfilePath:@"/homework/"];
  236. [UPLOAD_MANAGER videoUpload:fileData fileName:@"video" fileSuffix:suffix progress:^(int64_t bytesWritten, int64_t totalBytes) {
  237. int progress = (int)(bytesWritten / totalBytes * 100);
  238. __block NSString *tipsMessage = [NSString stringWithFormat:@"上传中 %d%%",progress];
  239. dispatch_main_async_safe(^{
  240. [LOADING_MANAGER.loadingView setDisplayText:tipsMessage];
  241. });
  242. } successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
  243. [LOADING_MANAGER removeCustomLoading];
  244. NSString *fileUrl = [fileUrlArray lastObject];
  245. self.isModify = YES;
  246. // 删除文件
  247. [self removeVideoWithPath:videoUrl];
  248. // 刷新弹窗
  249. [self evaluateSubmitViewWithSource:fileUrl];
  250. } faliure:^(NSError * _Nullable error, NSString * _Nullable descMessaeg) {
  251. [LOADING_MANAGER removeCustomLoading];
  252. if (![NSString isEmptyString:descMessaeg]) {
  253. [LOADING_MANAGER MBShowAUTOHidingInWindow:descMessaeg];
  254. }
  255. }];
  256. }
  257. - (void)evaluateSubmitViewWithSource:(NSString *)fileUrl {
  258. [self.submitAlertView.sourceArray addObject:fileUrl];
  259. [self.submitAlertView configWithFileArray:self.submitAlertView.sourceArray];
  260. }
  261. - (void)removeVideoWithPath:(NSString *)videoUrl {
  262. NSFileManager *fileMamager = [NSFileManager defaultManager];
  263. if ([fileMamager fileExistsAtPath:videoUrl]) {
  264. [fileMamager removeItemAtPath:videoUrl error:nil];
  265. }
  266. }
  267. // 播放
  268. - (void)playVideoIndex:(NSInteger)index {
  269. if (self.fileArray.count > index) {
  270. NSString *fileUrl = self.fileArray[index];
  271. [self playVideoWithUrl:fileUrl];
  272. }
  273. }
  274. // 删除
  275. - (void)deleteVideoIndex:(NSInteger)index {
  276. if (self.fileArray.count > index) {
  277. [self.fileArray removeObjectAtIndex:index];
  278. [self.tableView reloadData];
  279. }
  280. self.isModify = YES;
  281. }
  282. #pragma mark ------ WMPlayer
  283. - (void)playVideoWithUrl:(NSString *)fileUrl {
  284. fileUrl = [fileUrl getUrlEndcodeString];
  285. _playerFrame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  286. _wmPlayer = [[WMPlayer alloc] initWithFrame:_playerFrame];
  287. WMPlayerModel *playModel = [[WMPlayerModel alloc] init];
  288. playModel.videoURL = [NSURL URLWithString:fileUrl];
  289. _wmPlayer.playerModel = playModel;
  290. _wmPlayer.delegate = self;
  291. _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
  292. _bgView.backgroundColor = [UIColor blackColor];
  293. [[UIApplication sharedApplication].keyWindow addSubview:_bgView];
  294. [[UIApplication sharedApplication].keyWindow addSubview:_wmPlayer];
  295. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:_wmPlayer];
  296. [_wmPlayer play];
  297. }
  298. - (void)wmplayer:(WMPlayer *)wmplayer clickedCloseButton:(UIButton *)backBtn {
  299. [wmplayer removePlayer];
  300. [_bgView removeFromSuperview];
  301. [self setNeedsStatusBarAppearanceUpdate];
  302. }
  303. - (void)wmplayer:(WMPlayer *)wmplayer clickedFullScreenButton:(UIButton *)fullScreenBtn {
  304. self.isRatation = !self.isRatation;
  305. if (self.isRatation) {
  306. [wmplayer removeFromSuperview];
  307. [UIView animateWithDuration:1.0f animations:^{
  308. wmplayer.transform = CGAffineTransformMakeRotation(M_PI_2);
  309. } completion:^(BOOL finished) {
  310. wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  311. [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
  312. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
  313. }];
  314. }
  315. else {
  316. [wmplayer removeFromSuperview];
  317. [UIView animateWithDuration:1.0f animations:^{
  318. // 复原
  319. wmplayer.transform = CGAffineTransformIdentity;
  320. } completion:^(BOOL finished) {
  321. wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  322. [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
  323. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
  324. }];
  325. }
  326. }
  327. - (void)bottomButtonAction {
  328. [self tryJoinRoom];
  329. }
  330. - (void)submitHomeworkAction {
  331. if (self.isModify == NO) {
  332. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请先选择视频文件"];
  333. return;
  334. }
  335. if (self.submitAlertView.sourceArray.count == 0) {
  336. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请选择作业视频"];
  337. return;
  338. }
  339. NSString *attachment = [self.fileArray componentsJoinedByString:@","];
  340. [LOADING_MANAGER showCustomLoading:@"加载中..."];
  341. [KSNetworkingManager homeSubmitAction:KS_POST courseScheduleId:self.courseId attachment:attachment success:^(NSDictionary * _Nonnull dic) {
  342. [LOADING_MANAGER removeCustomLoading];
  343. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  344. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"作业提交成功"];
  345. [self removeSubmitAlert];
  346. [self requestCourseInfoMessage];
  347. self.isModify = NO;
  348. }
  349. else {
  350. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  351. }
  352. } faliure:^(NSError * _Nonnull error) {
  353. [LOADING_MANAGER removeCustomLoading];
  354. }];
  355. }
  356. - (void)removeSubmitAlert {
  357. [self.submitAlertView removeView];
  358. }
  359. #pragma mark --- lazying
  360. - (OnlineClassManager *)classManager {
  361. if (!_classManager) {
  362. _classManager = [[OnlineClassManager alloc] init];
  363. }
  364. return _classManager;
  365. }
  366. - (AccompanyDetailBottomView *)bottomView {
  367. if (!_bottomView) {
  368. _bottomView = [AccompanyDetailBottomView shareInstance];
  369. MJWeakSelf;
  370. [_bottomView sureAction:^{
  371. [weakSelf bottomButtonAction];
  372. }];
  373. }
  374. return _bottomView;
  375. }
  376. - (UITableView *)tableView {
  377. if (!_tableView) {
  378. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  379. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  380. _tableView.backgroundColor = [UIColor clearColor];
  381. _tableView.delegate = self;
  382. _tableView.dataSource = self;
  383. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  384. _tableView.showsHorizontalScrollIndicator = NO;
  385. _tableView.showsVerticalScrollIndicator = NO;
  386. _tableView.rowHeight = UITableViewAutomaticDimension;
  387. _tableView.estimatedRowHeight = 136.0f;
  388. [_tableView registerNib:[UINib nibWithNibName:@"MusicRoomCourseInfoCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MusicRoomCourseInfoCell"];
  389. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyArrangeCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyArrangeCell"];
  390. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyHomeworkCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyHomeworkCell"];
  391. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyRemarkCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyRemarkCell"];
  392. }
  393. return _tableView;
  394. }
  395. - (NSMutableAttributedString *)getAttrStringWithText:(NSString *)text {
  396. if (![NSString isEmptyString:text]) {
  397. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  398. [paragraphStyle setLineSpacing:6];//调整行间距
  399. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:text attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:16],NSForegroundColorAttributeName:HexRGB(0xffffff)}];
  400. return attr;
  401. }
  402. else {
  403. return [[NSMutableAttributedString alloc] initWithString:@""];
  404. }
  405. }
  406. - (void)tryJoinRoom {
  407. NSDateFormatter *dateFormatter = [NSObject getDateformatter];
  408. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  409. NSDate *beginDate = [dateFormatter dateFromString:self.homeworkModel.startTime];
  410. NSDate *endDate = [dateFormatter dateFromString:self.homeworkModel.endTime];
  411. NSDate *currentDate = [NSDate date];
  412. NSTimeInterval beginTimeInterval = [beginDate timeIntervalSinceDate:currentDate];
  413. NSTimeInterval endTimeInterval = [currentDate timeIntervalSinceDate:endDate];
  414. if (beginTimeInterval <= self.joinRoomBeforeTime * 60 && endTimeInterval < 0) {
  415. [self joinClassRoom];
  416. }
  417. else if (endTimeInterval > 0) {
  418. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"该课程已结束"];
  419. }
  420. else {
  421. NSString *tipsString = [NSString stringWithFormat:@"课程还未开始,请在上课前%zd分钟进入", self.joinRoomBeforeTime];
  422. [LOADING_MANAGER MBShowAUTOHidingInWindow:tipsString];
  423. }
  424. }
  425. // 加入房间
  426. - (void)joinClassRoom {
  427. // 加入房间前判断摄像头和麦克风逻辑
  428. [RecordCheckManager checkCameraPremissionAvaiableCallback:^(PREMISSIONTYPE type) {
  429. [self afterCheckCameraCheckMic:type];
  430. }];
  431. }
  432. - (void)afterCheckCameraCheckMic:(PREMISSIONTYPE)cameraType {
  433. [RecordCheckManager checkMicPermissionAvaiableCallback:^(PREMISSIONTYPE type) {
  434. if (type == PREMISSIONTYPE_YES && cameraType == PREMISSIONTYPE_YES) {
  435. // 判断是否进行课前检测
  436. [self.classManager joinRoomWithId:self.courseId subjectName:self.homeworkModel.subjectName classEndTime:self.homeworkModel.endTime inViewController:self];
  437. }
  438. else {
  439. NSString *content = @"";
  440. CHECKDEVICETYPE checkType = CHECKDEVICETYPE_BOTH;
  441. if (cameraType == PREMISSIONTYPE_NO && type == PREMISSIONTYPE_NO) {
  442. content = @"请开启相机和麦克风访问权限";
  443. checkType = CHECKDEVICETYPE_BOTH;
  444. }
  445. else if (cameraType == PREMISSIONTYPE_NO && type == PREMISSIONTYPE_YES) {
  446. content = @"请开启相机访问权限";
  447. checkType = CHECKDEVICETYPE_CAMREA;
  448. }
  449. else if (cameraType == PREMISSIONTYPE_YES && type == PREMISSIONTYPE_NO) {
  450. content = @"请开启麦克风访问权限";
  451. checkType = CHECKDEVICETYPE_MIC;
  452. }
  453. [self showAlertWithMessage:content type:checkType];
  454. }
  455. }];
  456. }
  457. - (void)showAlertWithMessage:(NSString *)message type:(CHECKDEVICETYPE)deviceType {
  458. [KSPremissionAlert shareInstanceDisplayImage:deviceType message:message showInView:self.view cancel:^{
  459. } confirm:^{
  460. [self openSettingView];
  461. }];
  462. }
  463. - (void)openSettingView {
  464. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
  465. }
  466. - (CourseGroupNavView *)navView {
  467. if (!_navView) {
  468. _navView = [CourseGroupNavView sharedInstance];
  469. MJWeakSelf;
  470. [_navView configWithNavTitle:@"课程详情" callback:^{
  471. [weakSelf backAction];
  472. }];
  473. }
  474. return _navView;
  475. }
  476. - (HomeworkSubmitAlertView *)submitAlertView {
  477. if (!_submitAlertView) {
  478. _submitAlertView = [HomeworkSubmitAlertView sharedInstance];
  479. MJWeakSelf;
  480. [_submitAlertView alertActionCallback:^(HOMEWORK_TYPE type, NSMutableArray * _Nonnull fileArray, NSInteger videoIndex) {
  481. [weakSelf alertAction:type fileArray:fileArray videoIndex:videoIndex];
  482. }];
  483. }
  484. return _submitAlertView;
  485. }
  486. - (void)alertAction:(HOMEWORK_TYPE)type fileArray:(NSMutableArray *)fileArray videoIndex:(NSInteger)videoIndex {
  487. switch (type) {
  488. case HOMEWORK_TYPE_ADD:
  489. {
  490. // 调用相册
  491. self.mediaManager = [[KSMediaManager alloc] init];
  492. self.mediaManager.mediaType = MEDIATYPE_VIDEO;
  493. self.mediaManager.maxPhotoNumber = 1;
  494. self.mediaManager.baseCtrl = self;
  495. self.mediaManager.needCropImage = NO;
  496. MJWeakSelf;
  497. [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
  498. NSLog(@"%@", videoUrl);
  499. // 上传视频
  500. [weakSelf uploadVideoWithUrl:videoUrl];
  501. }];
  502. [self.mediaManager pushImagePickerController];
  503. }
  504. break;
  505. case HOMEWORK_TYPE_SUBMIT:
  506. {
  507. [self submitHomeworkAction];
  508. }
  509. break;
  510. case HOMEWORK_TYPE_PLAY:
  511. {
  512. if (fileArray.count > videoIndex) {
  513. NSString *fileUrl = fileArray[videoIndex];
  514. [self playVideoWithUrl:fileUrl];
  515. }
  516. }
  517. break;
  518. case HOMEWORK_TYPE_DELETE:
  519. {
  520. self.isModify = YES;
  521. }
  522. break;
  523. default:
  524. break;
  525. }
  526. }
  527. /*
  528. #pragma mark - Navigation
  529. // In a storyboard-based application, you will often want to do a little preparation before navigation
  530. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  531. // Get the new view controller using [segue destinationViewController].
  532. // Pass the selected object to the new view controller.
  533. }
  534. */
  535. @end