RecordExamViewController.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. //
  2. // RecordExamViewController.m
  3. // MusicGradeExam
  4. //
  5. // Created by Kyle on 2020/7/22.
  6. // Copyright © 2020 DayaMusic. All rights reserved.
  7. //
  8. #import "RecordExamViewController.h"
  9. #import "RecordBodyView.h"
  10. #import "RecordListCell.h"
  11. #import "RecordBottomView.h"
  12. #import "RecordTipsView.h"
  13. #import "WMPlayer.h"
  14. #import "SongModel.h"
  15. #import "KSGuideMaskView.h"
  16. #import "KSNormalAlertView.h"
  17. #import "KSVideoRecordViewController.h"
  18. #import "TZImageManager.h"
  19. @interface RecordExamViewController ()<UITableViewDelegate, UITableViewDataSource,WMPlayerDelegate>
  20. {
  21. WMPlayer *_wmPlayer;
  22. CGRect _playerFrame;
  23. }
  24. @property (nonatomic, assign) BOOL isRatation;
  25. @property (nonatomic, strong) UIView *bgView;
  26. @property (nonatomic, strong) RecordBodyView *topView;
  27. @property (nonatomic, strong) RecordTipsView *tipsView;
  28. @property (nonatomic, strong) UITableView *tableView;
  29. @property (nonatomic, strong) RecordBottomView *bottomView;
  30. @property (nonatomic, strong) NSMutableArray *songArray;
  31. @property (strong, nonatomic) MBProgressHUD *HUD;
  32. @property (nonatomic, strong) NSMutableArray *fileUrlArray;
  33. @property (nonatomic, assign) BOOL hasShowTips;
  34. @end
  35. @implementation RecordExamViewController
  36. - (void)viewDidLoad {
  37. [super viewDidLoad];
  38. // Do any additional setup after loading the view.
  39. self.ks_prefersNavigationBarHidden = YES;
  40. [self configUI];
  41. if (self.sourceModel) {
  42. [self evaluateSource];
  43. }
  44. else {
  45. [self requestData];
  46. }
  47. }
  48. - (void)viewWillAppear:(BOOL)animated {
  49. [super viewWillAppear:animated];
  50. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  51. }
  52. - (void)viewDidDisappear:(BOOL)animated {
  53. [super viewDidDisappear:animated];
  54. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
  55. if(@available(iOS 13.0, *)){
  56. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDarkContent;
  57. }
  58. }
  59. - (void)requestData {
  60. [self showhud];
  61. [KSRequestManager stuRecordDetailRequest:KS_GET examRegistrationId:self.examRegistrationId success:^(NSDictionary * _Nonnull dic) {
  62. [self removehub];
  63. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  64. self.sourceModel = [[RecordExamModel alloc] initWithDictionary:[dic dictionaryValueForKey:@"data"]];
  65. [self evaluateSource];
  66. }
  67. else {
  68. [self MBPShow:MESSAGEKEY];
  69. }
  70. } faliure:^(NSError * _Nonnull error) {
  71. [self removehub];
  72. }];
  73. }
  74. - (void)evaluateSource {
  75. if (self.sourceModel == nil) {
  76. return;
  77. }
  78. [self.topView configTime:[NSString stringWithFormat:@"%.0f", self.sourceModel.subTime]];
  79. [self.tipsView configWithEndTime:self.sourceModel.examEndTime];
  80. NSData *songDate = [self.sourceModel.songJson dataUsingEncoding:NSUTF8StringEncoding];
  81. NSArray *listArray = [NSJSONSerialization JSONObjectWithData:songDate options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
  82. NSMutableArray *songList = [NSMutableArray array];
  83. for (NSDictionary *parm in listArray) {
  84. SongModel *model = [[SongModel alloc] initWithDictionary:parm];
  85. [songList addObject:model];
  86. }
  87. self.songArray = [NSMutableArray arrayWithArray:songList];
  88. for (NSInteger i = 0; i < self.songArray.count; i++) {
  89. SongModel *model = self.songArray[i];
  90. NSString *fileKey = [NSString stringWithFormat:@"%@%@", self.examRegistrationId, model.songName];
  91. NSDictionary *fileMessage = UserDefault(fileKey);
  92. if (fileMessage) {
  93. NSString *remoteUrl = [fileMessage stringValueForKey:@"remoteUrl"];
  94. [self.fileUrlArray addObject:remoteUrl];
  95. }
  96. }
  97. [self checkSubmitButtonEnable];
  98. [self.tableView reloadData];
  99. }
  100. - (void)configUI {
  101. [self.view addSubview:self.topView];
  102. [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
  103. make.top.left.right.mas_equalTo(self.view);
  104. make.height.mas_equalTo(self.view.mas_width).multipliedBy(79.0 / 207).offset(11);
  105. }];
  106. [self.view addSubview:self.bottomView];
  107. [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  108. make.left.right.mas_equalTo(self.view);
  109. make.bottom.mas_equalTo(self.view.mas_bottomMargin);
  110. make.height.mas_equalTo(90);
  111. }];
  112. [self.view addSubview:self.tableView];
  113. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  114. make.left.right.mas_equalTo(self.view);
  115. make.top.mas_equalTo(self.topView.mas_bottom);
  116. make.bottom.mas_equalTo(self.bottomView.mas_top);
  117. }];
  118. }
  119. - (void)viewDidAppear:(BOOL)animated {
  120. [super viewDidAppear:animated];
  121. if (_hasShowTips == NO) {
  122. [self addIntroduceView];
  123. }
  124. }
  125. - (void)addIntroduceView {
  126. _hasShowTips = YES;
  127. CGRect rect1 = [self.tableView convertRect:self.tableView.tableHeaderView.frame toView:[UIApplication sharedApplication].keyWindow];
  128. rect1.origin.y -= 50;
  129. rect1.size.height += 50;
  130. UIBezierPath *pathOne = [UIBezierPath bezierPathWithRect:rect1];
  131. CGRect rect2 = rect1;
  132. rect2.size = CGSizeMake(kScreenWidth, 130);
  133. rect2.origin.y = CGRectGetMaxY(rect1);
  134. UIBezierPath *pathSecond = [UIBezierPath bezierPathWithRect:rect2];
  135. NSArray *tipsArray = @[@"请在录播时间内完成视频上传", @"点击上传曲目录播视频"];
  136. NSArray *bezierArray = @[pathOne,pathSecond];
  137. KSGuideMaskView *guideView = [[KSGuideMaskView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
  138. [guideView addTips:tipsArray transparentRect:bezierArray shaperLayerIndex:-1];
  139. [guideView showMaskViewInView:nil];
  140. }
  141. #pragma mark ----- table data source
  142. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  143. return self.songArray.count;
  144. }
  145. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  146. SongModel *model = self.songArray[indexPath.row];
  147. RecordListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RecordListCell"];
  148. MJWeakSelf;
  149. [cell configCellWithSource:model examRegistrationId:self.examRegistrationId operationCallback:^(RECORDTYPE type, NSString *fileKey) {
  150. [weakSelf opreationCellType:type fileKey:fileKey index:indexPath.row];
  151. }];
  152. return cell;
  153. }
  154. - (void)opreationCellType:(RECORDTYPE)type fileKey:(NSString *)fileKey index:(NSInteger)cellIndex {
  155. if (type == RECORDTYPE_RECORD) { // 录像
  156. NSMutableArray *songNameArray = [NSMutableArray array];
  157. for (NSInteger i = 0; i < self.songArray.count; i++) {
  158. if (i >= cellIndex) {
  159. // 从选择的开始->后面未录制的添加到待录制里
  160. SongModel *model = self.songArray[i];
  161. NSString *fileKey = [NSString stringWithFormat:@"%@%@", self.examRegistrationId, model.songName];
  162. NSDictionary *fileMessage = UserDefault(fileKey);
  163. if (fileMessage == nil) {
  164. [songNameArray addObject:model.songName];
  165. }
  166. }
  167. }
  168. KSVideoRecordViewController *recordCtrl = [[KSVideoRecordViewController alloc] init];
  169. recordCtrl.subjectName = self.subjectName;
  170. recordCtrl.leverName = self.leverName;
  171. recordCtrl.songMessageArray = songNameArray;
  172. recordCtrl.singleSongRecordMinutes = self.sourceModel.singleSongRecordMinutes;
  173. [recordCtrl configTime:self.topView.duration recordFinishBlock:^(VIDEORECORDACTION action, NSMutableArray *videoArray) {
  174. [self uploadVideoWithVideoArray:videoArray songArray:songNameArray];
  175. }];
  176. recordCtrl.modalPresentationStyle = UIModalPresentationFullScreen;
  177. [self presentViewController:recordCtrl animated:YES completion:nil];
  178. }
  179. else { // 删除
  180. [self deleteFileWithKey:fileKey];
  181. }
  182. }
  183. - (void)uploadVideoWithVideoArray:(NSMutableArray *)videoArray songArray:(NSArray *)songArray {
  184. dispatch_main_async_safe(^{
  185. [MBProgressHUD ksShowHUDWithText:@"视频处理中..."];
  186. });
  187. NSMutableArray *urlArray = [NSMutableArray array];
  188. NSMutableArray *fileKeyArray = [NSMutableArray array];
  189. MJWeakSelf;
  190. for (NSInteger index = 0 ;index < videoArray.count; index++) {
  191. PHAsset *assset = videoArray[index];
  192. [[TZImageManager manager] getVideoOutputPathWithAsset:assset presetName:AVAssetExportPresetMediumQuality success:^(NSString *outputPath) {
  193. NSLog(@"视频导出到本地完成,沙盒路径为:%@",outputPath);
  194. NSData *outputData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:outputPath]]; //压缩后的视频
  195. NSLog(@"导出后的视频:%@",[NSString stringWithFormat:@"%.2fM",(CGFloat)outputData.length/(1024*1024)]);
  196. NSString *fileKey = [NSString stringWithFormat:@"%@%@", self.examRegistrationId, songArray[index]];
  197. [urlArray addObject:outputPath];
  198. [fileKeyArray addObject:fileKey];
  199. if (index == videoArray.count - 1) {
  200. [MBProgressHUD ksHideHUD];
  201. // 批量上传
  202. [weakSelf mutilUploadVideoWithUrl:urlArray fileKeyArray:fileKeyArray];
  203. }
  204. } failure:^(NSString *errorMessage, NSError *error) {
  205. dispatch_main_async_safe(^{
  206. [MBProgressHUD ksShowMessage:@"视频导出失败"];
  207. [MBProgressHUD ksHideHUD];
  208. });
  209. }];
  210. }
  211. }
  212. - (void)deleteFileWithKey:(NSString *)fileKey {
  213. NSDictionary *parm = UserDefault(fileKey);
  214. NSString *localUrl = [parm stringValueForKey:@"localFileUrl"];
  215. [self removeVideoWithPath:localUrl];
  216. UserDefaultRemoveObjectForKey(fileKey);
  217. NSString *remoteUrl = [parm stringValueForKey:@"remoteUrl"];
  218. [self.fileUrlArray removeObject:remoteUrl];
  219. [self checkSubmitButtonEnable];
  220. [self.tableView reloadData];
  221. }
  222. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  223. RecordListCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  224. if (cell.fileMessage) {
  225. // 播放
  226. NSString *localUrl = [cell.fileMessage stringValueForKey:@"localFileUrl"];
  227. if ([[NSFileManager defaultManager] fileExistsAtPath:localUrl]) {
  228. [self playVideoWithUrl:[NSURL fileURLWithPath:localUrl]];
  229. }
  230. else {
  231. NSString *remoteUrl = [cell.fileMessage stringValueForKey:@"remoteUrl"];
  232. [self playVideoWithUrl:[NSURL URLWithString:remoteUrl]];
  233. }
  234. }
  235. }
  236. - (void)checkSubmitButtonEnable {
  237. if (self.fileUrlArray.count == 0) {
  238. self.bottomView.finishButton.userInteractionEnabled = NO;
  239. [self.bottomView.finishButton setBackgroundImage:[UIImage imageNamed:@"button_unable"] forState:UIControlStateNormal];
  240. }
  241. else {
  242. self.bottomView.finishButton.userInteractionEnabled = YES;
  243. [self.bottomView.finishButton setBackgroundImage:[UIImage imageNamed:@"button_nomal"] forState:UIControlStateNormal];
  244. [self.bottomView.finishButton setBackgroundImage:[UIImage imageNamed:@"button_highlight"] forState:UIControlStateHighlighted];
  245. }
  246. }
  247. #pragma mark --- lazying
  248. - (RecordBodyView *)topView {
  249. if (!_topView) {
  250. _topView = [RecordBodyView shareInstance];
  251. _topView.topTitleLabel.text = @"录播考试";
  252. MJWeakSelf;
  253. [_topView topviewAction:^(RECORDTOPACTION action) {
  254. [weakSelf backOrEndAction:action];
  255. }];
  256. }
  257. return _topView;
  258. }
  259. - (void)backOrEndAction:(RECORDTOPACTION)action {
  260. if (action == RECORDTOPACTION_BACK) {
  261. [self.navigationController popViewControllerAnimated:YES];
  262. }
  263. else { // 时间结束
  264. MJWeakSelf;
  265. if (self.fileUrlArray.count == 0) {
  266. [self KSShowMsg:@"考试结束" promptCompletion:^{
  267. [weakSelf.navigationController popViewControllerAnimated:YES];
  268. }];
  269. }
  270. else {
  271. [KSNormalAlertView ks_showAlertWithTitle:@"考试时间已结束,是否提交?" leftTitle:@"取消" rightTitle:@"确定" cancel:^{
  272. [weakSelf removeAllFile];
  273. [weakSelf.navigationController popViewControllerAnimated:YES];
  274. } confirm:^{
  275. [weakSelf submitService];
  276. }];
  277. }
  278. }
  279. }
  280. - (RecordTipsView *)tipsView {
  281. if (!_tipsView) {
  282. _tipsView = [RecordTipsView shareInstance];
  283. }
  284. return _tipsView;
  285. }
  286. - (UITableView *)tableView {
  287. if (!_tableView) {
  288. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  289. _tableView.delegate = self;
  290. _tableView.dataSource = self;
  291. _tableView.rowHeight = 130;
  292. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  293. _tableView.backgroundColor = HexRGB(0xf5f5f5);
  294. _tableView.showsVerticalScrollIndicator = NO;
  295. [_tableView registerNib:[UINib nibWithNibName:@"RecordListCell" bundle:nil] forCellReuseIdentifier:@"RecordListCell"];
  296. _tableView.tableHeaderView = self.tipsView;
  297. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
  298. bottomView.backgroundColor = HexRGB(0xf3f4f8);
  299. _tableView.tableFooterView = bottomView;
  300. }
  301. return _tableView;
  302. }
  303. - (RecordBottomView *)bottomView {
  304. if (!_bottomView) {
  305. _bottomView = [RecordBottomView shareInstance];
  306. MJWeakSelf;
  307. [_bottomView submitMediaAction:^{
  308. [weakSelf submitAction];
  309. }];
  310. }
  311. return _bottomView;
  312. }
  313. - (void)submitAction {
  314. // 是否确认提交
  315. MJWeakSelf;
  316. [KSNormalAlertView ks_showAlertWithTitle:@"请确认已上传所有录播曲目" leftTitle:@"取消" rightTitle:@"确认" cancel:^{
  317. } confirm:^{
  318. [weakSelf submitService];
  319. }];
  320. }
  321. // // 提交 完成考试
  322. - (void)submitService {
  323. [self showhud];
  324. NSString *videoUrl = [self.fileUrlArray componentsJoinedByString:@","];
  325. [KSRequestManager stuEndRecordFinishRequest:KS_POST examRegistrationId:self.examRegistrationId videoUrl:videoUrl success:^(NSDictionary * _Nonnull dic) {
  326. [self removehub];
  327. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  328. MJWeakSelf;
  329. [self removeAllFile];
  330. [self KSShowMsg:@"提交成功" promptCompletion:^{
  331. [weakSelf.topView stopDurationTimer];
  332. [weakSelf.navigationController popViewControllerAnimated:YES];
  333. }];
  334. }
  335. else {
  336. [self MBPShow:MESSAGEKEY];
  337. }
  338. } faliure:^(NSError * _Nonnull error) {
  339. [self removehub];
  340. }];
  341. }
  342. - (void)removeAllFile {
  343. for (NSInteger i = 0; i < self.songArray.count; i++) {
  344. SongModel *model = self.songArray[i];
  345. NSString *fileKey = [NSString stringWithFormat:@"%@%@", self.examRegistrationId, model.songName];
  346. NSDictionary *fileMessage = UserDefault(fileKey);
  347. if (fileMessage) {
  348. NSString *localUrl = [fileMessage stringValueForKey:@"localFileUrl"];
  349. UserDefaultRemoveObjectForKey(fileKey);
  350. [self removeVideoWithPath:localUrl];
  351. }
  352. }
  353. }
  354. #pragma mark ------ 上传视频文件
  355. - (void)mutilUploadVideoWithUrl:(NSMutableArray *)videoUrlArray fileKeyArray:(NSMutableArray *)fileKeyArray {
  356. [self hudTipWillShow:YES];
  357. NSMutableArray *fileDataArray = [NSMutableArray array];
  358. for (NSString *videoUrl in videoUrlArray) {
  359. [fileDataArray addObject:[NSData dataWithContentsOfURL:[NSURL fileURLWithPath:videoUrl]]];
  360. }
  361. [KSRequestManager mutiVideoFileUpload:KS_POST fileDataArray:fileDataArray progress:^(int64_t bytesWritten, int64_t totalBytes) {
  362. dispatch_main_async_safe(^{
  363. // 显示进度
  364. if (self.HUD) {
  365. self.HUD.progress = bytesWritten / totalBytes;// progress是回调进度
  366. }
  367. });
  368. } success:^(NSArray * _Nonnull dics) {
  369. [self hudTipWillShow:NO];
  370. for (NSInteger index = 0; index < dics.count; index++) {
  371. NSDictionary *dic = [dics objectAtIndex:index];
  372. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  373. NSString *fileUrl = [[dic dictionaryValueForKey:@"data"] stringValueForKey:@"url"];
  374. NSString *fileName = [[fileUrl componentsSeparatedByString:@"/"] lastObject];
  375. NSString *videoUrl = [fileDataArray objectAtIndex:index];
  376. NSString *fileKey = [fileKeyArray objectAtIndex:index];
  377. // 保存文件路径
  378. NSDictionary *parm = @{@"localFileUrl":videoUrl,
  379. @"remoteUrl":fileUrl,
  380. @"fileName": fileName};
  381. UserDefaultSet(parm, fileKey);
  382. [self.fileUrlArray addObject:fileUrl];
  383. [self checkSubmitButtonEnable];
  384. }
  385. else {
  386. [self MBPShow:MESSAGEKEY];
  387. }
  388. }
  389. [self.tableView reloadData];
  390. } faliure:^(NSError * _Nonnull error) {
  391. [self hudTipWillShow:NO];
  392. }];
  393. }
  394. - (void)uploadVideoWithUrl:(NSString *)videoUrl fileKey:(NSString *)fileKey {
  395. [self hudTipWillShow:YES];
  396. NSData *fileData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:videoUrl]];
  397. [KSRequestManager videoFileUpload:KS_POST fileData:fileData progress:^(int64_t bytesWritten, int64_t totalBytes) {
  398. dispatch_main_async_safe(^{
  399. // 显示进度
  400. if (self.HUD) {
  401. self.HUD.progress = bytesWritten / totalBytes;// progress是回调进度
  402. }
  403. });
  404. } success:^(NSDictionary * _Nonnull dic) {
  405. [self hudTipWillShow:NO];
  406. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  407. NSString *fileUrl = [[dic dictionaryValueForKey:@"data"] stringValueForKey:@"url"];
  408. NSString *fileName = [[fileUrl componentsSeparatedByString:@"/"] lastObject];
  409. // 保存文件路径
  410. NSDictionary *parm = @{@"localFileUrl":videoUrl,
  411. @"remoteUrl":fileUrl,
  412. @"fileName": fileName};
  413. UserDefaultSet(parm, fileKey);
  414. [self.tableView reloadData];
  415. [self.fileUrlArray addObject:fileUrl];
  416. [self checkSubmitButtonEnable];
  417. }
  418. else {
  419. [self MBPShow:MESSAGEKEY];
  420. }
  421. } faliure:^(NSError * _Nonnull error) {
  422. [self hudTipWillShow:NO];
  423. }];
  424. }
  425. - (void)removeVideoWithPath:(NSString *)videoUrl {
  426. NSFileManager *fileMamager = [NSFileManager defaultManager];
  427. if ([fileMamager fileExistsAtPath:videoUrl]) {
  428. [fileMamager removeItemAtPath:videoUrl error:nil];
  429. }
  430. }
  431. - (void)hudTipWillShow:(BOOL)willShow{
  432. if (willShow) {
  433. [self resignFirstResponder];
  434. UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
  435. if (!_HUD) {
  436. _HUD = [MBProgressHUD showHUDAddedTo:keyWindow animated:YES];
  437. _HUD.mode = MBProgressHUDModeDeterminateHorizontalBar;
  438. _HUD.label.text = @"正在转码视频...";
  439. _HUD.removeFromSuperViewOnHide = YES;
  440. }else{
  441. _HUD.progress = 0;
  442. [keyWindow addSubview:_HUD];
  443. [_HUD showAnimated:YES];
  444. }
  445. }else{
  446. [_HUD hideAnimated:YES];
  447. }
  448. }
  449. - (NSMutableArray *)fileUrlArray {
  450. if (!_fileUrlArray) {
  451. _fileUrlArray = [NSMutableArray arrayWithCapacity:self.songArray.count];
  452. }
  453. return _fileUrlArray;
  454. }
  455. #pragma mark ------- 播放文件
  456. - (void)playVideoWithUrl:(NSURL *)fileUrl {
  457. _playerFrame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  458. _wmPlayer = [[WMPlayer alloc] initWithFrame:_playerFrame];
  459. WMPlayerModel *playModel = [[WMPlayerModel alloc] init];
  460. playModel.videoURL = fileUrl;
  461. _wmPlayer.playerModel = playModel;
  462. _wmPlayer.delegate = self;
  463. _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
  464. _bgView.backgroundColor = [UIColor blackColor];
  465. [[UIApplication sharedApplication].keyWindow addSubview:_bgView];
  466. [[UIApplication sharedApplication].keyWindow addSubview:_wmPlayer];
  467. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:_wmPlayer];
  468. [_wmPlayer play];
  469. }
  470. - (void)wmplayer:(WMPlayer *)wmplayer clickedCloseButton:(UIButton *)backBtn {
  471. [wmplayer removePlayer];
  472. [_bgView removeFromSuperview];
  473. [self setNeedsStatusBarAppearanceUpdate];
  474. }
  475. - (void)wmplayer:(WMPlayer *)wmplayer clickedFullScreenButton:(UIButton *)fullScreenBtn {
  476. self.isRatation = !self.isRatation;
  477. if (self.isRatation) {
  478. [wmplayer removeFromSuperview];
  479. [UIView animateWithDuration:1.0f animations:^{
  480. wmplayer.transform = CGAffineTransformMakeRotation(M_PI_2);
  481. } completion:^(BOOL finished) {
  482. wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  483. [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
  484. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
  485. }];
  486. }
  487. else {
  488. [wmplayer removeFromSuperview];
  489. [UIView animateWithDuration:1.0f animations:^{
  490. // 复原
  491. wmplayer.transform = CGAffineTransformIdentity;
  492. } completion:^(BOOL finished) {
  493. wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  494. [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
  495. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
  496. }];
  497. }
  498. }
  499. - (void)dealloc {
  500. [self.topView stopDurationTimer];
  501. }
  502. /*
  503. #pragma mark - Navigation
  504. // In a storyboard-based application, you will often want to do a little preparation before navigation
  505. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  506. // Get the new view controller using [segue destinationViewController].
  507. // Pass the selected object to the new view controller.
  508. }
  509. */
  510. @end