YBVideoMusicView.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. #import "YBVideoMusicView.h"
  2. #import "MusicModel.h"
  3. #import "MusicCell.h"
  4. #import "NSString+StringSize.h"
  5. #import "TCVideoRecordViewController.h"
  6. #import "MusicHeaderView.h"
  7. #import "MusicClassVC.h"
  8. #import "JCHATAlertViewWait.h"
  9. #import <MediaPlayer/MediaPlayer.h>
  10. @interface YBVideoMusicView ()<UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate> {
  11. UIButton *btn;
  12. CGFloat classHeight; //分类的高度
  13. int _paging;
  14. AVAudioPlayer *_musicPlayer; //音乐播放器
  15. BOOL _isSearch; //当前显示 是否是 搜索
  16. BOOL _isColl; //NO - 当前显示是top10 YES - 当前显示是收藏
  17. CGFloat _originVolume; //记录系统音量
  18. MPVolumeView *_volumeView;
  19. UISlider *_volumeViewSlider;
  20. BOOL _changeVolume;
  21. }
  22. @property(nonatomic,strong)UIView *searchBg; //搜索框背景
  23. @property(nonatomic,strong)UISearchBar *search;
  24. @property(nonatomic,strong)MusicHeaderView *musicClassV; //音乐分类
  25. /** 记录 cell 是否打开 */
  26. @property (nonatomic, assign) BOOL isOpen;
  27. /** 记录当前点击的 cell 行数 */
  28. @property (nonatomic, assign) int curRow;
  29. @property(nonatomic,strong)UITableView *tableView;
  30. @property(nonatomic,strong)NSArray *models;
  31. @property(nonatomic,strong)NSMutableArray *allArray;
  32. @end
  33. @implementation YBVideoMusicView
  34. -(void)creatVoluem {
  35. if (_volumeViewSlider == nil) {
  36. _volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(-100, -100, 40, 40)];
  37. [self.view addSubview:_volumeView];
  38. for (UIView* newView in _volumeView.subviews) {
  39. if ([newView.class.description isEqualToString:@"MPVolumeSlider"]){
  40. _volumeViewSlider = (UISlider*)newView;
  41. break;
  42. }
  43. }
  44. }
  45. [_volumeView setHidden:NO];
  46. [_volumeView setShowsRouteButton:YES];
  47. [_volumeView setShowsVolumeSlider:YES];
  48. }
  49. -(void)recoveryVolume{
  50. if (_changeVolume) {
  51. _changeVolume = NO;
  52. _volumeViewSlider.value = _originVolume ;
  53. }
  54. }
  55. -(void)viewDidAppear:(BOOL)animated {
  56. [super viewDidAppear:animated];
  57. if ([PublicObj getSysOutputVolume] < 0.2) {
  58. _changeVolume = YES;
  59. _originVolume = [AVAudioSession sharedInstance].outputVolume;
  60. _volumeViewSlider.value = 0.3;
  61. }
  62. }
  63. -(void)viewWillDisappear:(BOOL)animated {
  64. [super viewWillDisappear:animated];
  65. //指示器消失
  66. [PublicView indictorHide];
  67. }
  68. -(void)viewWillAppear:(BOOL)animated{
  69. [super viewWillAppear:animated];
  70. //指示器消失
  71. [PublicView indictorHide];
  72. _isSearch = NO;
  73. _search.text = @"";
  74. [self resetAttribute];
  75. [self recoveryHeight];
  76. if (_isColl == NO) {
  77. //重新加载热门
  78. [self pullTopTenMusic];
  79. }else{
  80. [self pullCollectMusic];
  81. }
  82. }
  83. - (void)viewDidLoad {
  84. [super viewDidLoad];
  85. self.view.backgroundColor = [UIColor whiteColor];
  86. self.navigationController.navigationBarHidden = YES;
  87. self.naviView.hidden = YES;
  88. [UIApplication sharedApplication].statusBarHidden = NO;
  89. [self creatVoluem];
  90. [self creatNavi];
  91. _paging = 1;
  92. _isSearch = NO;
  93. _isColl = NO;
  94. self.curRow = -1;
  95. self.allArray = [NSMutableArray array];
  96. self.models = [NSArray array];
  97. [self.view addSubview:self.searchBg];
  98. [self.view addSubview:self.musicClassV];
  99. [self.view addSubview:self.tableView];
  100. }
  101. -(void)resetAttribute {
  102. self.isOpen = NO;
  103. self.curRow = -1;
  104. _paging = 1;
  105. self.allArray = nil;
  106. self.allArray = [NSMutableArray array];
  107. [self.tableView reloadData];
  108. }
  109. #pragma mark - top10
  110. -(void)pullTopTenMusic {
  111. YBWeakSelf;
  112. [YBNetworking postWithUrl:@"Music.hotLists" Dic:nil Suc:^(int code, id info, NSString *msg) {
  113. [_tableView.mj_header endRefreshing];
  114. [_tableView.mj_footer endRefreshing];
  115. if (code == 0) {
  116. NSArray *infoA = [NSArray arrayWithArray:info];
  117. if (_paging == 1) {
  118. [self.allArray removeAllObjects];
  119. }
  120. if (infoA.count<=0) {
  121. [_tableView.mj_footer endRefreshingWithNoMoreData];
  122. }else {
  123. [self.allArray addObjectsFromArray:infoA];
  124. }
  125. if (self.allArray.count==0) {
  126. [PublicView showTextNoData:weakSelf.tableView text1:YZMsg(@"对不起") text2:YZMsg(@"没有搜索到相关内容") centerY:0.8];
  127. }else{
  128. [PublicView hiddenTextNoData:weakSelf.tableView];
  129. }
  130. [self.tableView reloadData];
  131. }else{
  132. [PublicView showTextNoData:weakSelf.tableView text1:YZMsg(@"对不起") text2:YZMsg(@"没有搜索到相关内容") centerY:0.8];
  133. [MBProgressHUD showPop:msg];
  134. }
  135. } Fail:^(id fail) {
  136. [_tableView.mj_header endRefreshing];
  137. [_tableView.mj_footer endRefreshing];
  138. }];
  139. }
  140. #pragma mark 收藏
  141. -(void)pullCollectMusic {
  142. YBWeakSelf;
  143. [YBNetworking postWithUrl:@"Music.getCollectMusicLists" Dic:@{@"p":@(_paging)} Suc:^(int code, id info, NSString *msg) {
  144. [_tableView.mj_header endRefreshing];
  145. [_tableView.mj_footer endRefreshing];
  146. if (code == 0) {
  147. NSArray *infoA = [NSArray arrayWithArray:info];
  148. if (_paging == 1) {
  149. [self.allArray removeAllObjects];
  150. }
  151. if (infoA.count<=0) {
  152. [_tableView.mj_footer endRefreshingWithNoMoreData];
  153. }else {
  154. [self.allArray addObjectsFromArray:infoA];
  155. }
  156. if (self.allArray.count==0) {
  157. [PublicView showTextNoData:weakSelf.tableView text1:@"" text2:YZMsg(@"没有收藏音乐") centerY:0.8];
  158. }else{
  159. [PublicView hiddenTextNoData:weakSelf.tableView];
  160. }
  161. [self.tableView reloadData];
  162. }else{
  163. [PublicView showTextNoData:weakSelf.tableView text1:@"" text2:YZMsg(@"没有收藏音乐") centerY:0.8];
  164. [MBProgressHUD showPop:msg];
  165. }
  166. } Fail:^(id fail) {
  167. [_tableView.mj_header endRefreshing];
  168. [_tableView.mj_footer endRefreshing];
  169. }];
  170. }
  171. #pragma mark - 搜索
  172. -(void)pullSearchMusic {
  173. NSString *url = [NSString stringWithFormat:@"Music.searchMusic&key=%@&p=%d&uid=%@",self.search.text,_paging,[Config getOwnID]];
  174. url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  175. YBWeakSelf;
  176. [YBNetworking postWithUrl:url Dic:nil Suc:^(int code, id info, NSString *msg) {
  177. [_tableView.mj_header endRefreshing];
  178. [_tableView.mj_footer endRefreshing];
  179. if (code == 0) {
  180. //指示器消失
  181. [PublicView indictorHide];
  182. NSArray *infoA = [NSArray arrayWithArray:info];
  183. if (_paging == 1) {
  184. [self.allArray removeAllObjects];
  185. }
  186. if (infoA.count<=0) {
  187. [_tableView.mj_footer endRefreshingWithNoMoreData];
  188. }else {
  189. [self.allArray addObjectsFromArray:infoA];
  190. }
  191. if (self.allArray.count ==0) {
  192. [PublicView showTextNoData:weakSelf.tableView text1:YZMsg(@"对不起") text2:YZMsg(@"没有搜索到相关内容") centerY:0.8];
  193. }else{
  194. [PublicView hiddenTextNoData:weakSelf.tableView];
  195. }
  196. [self.tableView reloadData];
  197. }else{
  198. [PublicView showTextNoData:weakSelf.tableView text1:YZMsg(@"对不起") text2:YZMsg(@"没有搜索到相关内容") centerY:0.8];
  199. [MBProgressHUD showPop:msg];
  200. //指示器消失
  201. [PublicView indictorHide];
  202. }
  203. } Fail:^(id fail) {
  204. //指示器消失
  205. [PublicView indictorHide];
  206. [_tableView.mj_header endRefreshing];
  207. [_tableView.mj_footer endRefreshing];
  208. }];
  209. }
  210. -(NSArray *)models{
  211. NSMutableArray *array = [NSMutableArray array];
  212. for (NSDictionary *dic in self.allArray) {
  213. MusicModel *model = [MusicModel modelWithDic:dic];
  214. [array addObject:model];
  215. }
  216. _models = array;
  217. return _models;
  218. }
  219. #pragma mark - 点击事件
  220. -(void)keyHide{
  221. [self.search resignFirstResponder];
  222. }
  223. #pragma mark - 音乐播放、暂停
  224. -(void)playMusic:(NSString *)path currentCell:(MusicCell *)cell currentIndex:(NSIndexPath*)indexPath{
  225. NSLog(@"播放");
  226. if (self.curRow !=indexPath.row) {
  227. //点击过cell并且非同一行时候,清除掉上一个播放器
  228. [self stopMusic];
  229. }
  230. if (!_musicPlayer) {
  231. //创建音乐播放器
  232. NSError *error = nil;
  233. _musicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];
  234. //准备播放
  235. _musicPlayer.volume = 0.8;
  236. [_musicPlayer prepareToPlay];
  237. //播放歌曲
  238. [_musicPlayer play];
  239. _musicPlayer.numberOfLoops = -1;
  240. [cell.StateBtn setImage:[UIImage imageNamed:@"music_pause"] forState:0];
  241. }else {
  242. if (_musicPlayer.isPlaying) {
  243. [_musicPlayer pause];
  244. [cell.StateBtn setImage:[UIImage imageNamed:@"music_play"] forState:0];
  245. }else {
  246. [_musicPlayer play];
  247. [cell.StateBtn setImage:[UIImage imageNamed:@"music_pause"] forState:0];
  248. }
  249. }
  250. }
  251. -(void)stopMusic {
  252. if (_musicPlayer) {
  253. [_musicPlayer stop];
  254. _musicPlayer = nil;
  255. }
  256. }
  257. #pragma mark - tableview UITableViewDataSource UITableViewDelegate
  258. //删除
  259. //-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
  260. //
  261. // MusicModel *model = _models[indexPath.row];
  262. // NSFileManager* fileManager=[NSFileManager defaultManager];
  263. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  264. // NSString *docDir = [paths objectAtIndex:0];
  265. // NSString *loadPath = [docDir stringByAppendingFormat:@"/*%@*%@*%@*%@.mp3",model.musicNameStr,model.singerStr,model.timeStr,model.songID];
  266. // BOOL blHave=[[NSFileManager defaultManager] fileExistsAtPath:loadPath];
  267. // if (blHave) {
  268. // [fileManager removeItemAtPath:loadPath error:nil];
  269. // [self.tableView reloadData];
  270. // [MBProgressHUD showPop:@"音乐缓存清除成功"];
  271. // }else{
  272. // [MBProgressHUD showPop:@"音乐缓存为空"];
  273. // }
  274. // [self stopMusic];
  275. //
  276. //}
  277. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  278. return self.models.count;
  279. }
  280. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  281. MusicCell *cell = [MusicCell cellWithTab:tableView andIndexPath:indexPath];
  282. //10-31添加
  283. (self.curRow == (int)indexPath.row && self.isOpen) ? (cell.startRecoedBtn.hidden = NO) : (cell.startRecoedBtn.hidden = YES);
  284. cell.backgroundColor = [UIColor whiteColor];
  285. MusicModel *model = _models[indexPath.row];
  286. cell.model = model;
  287. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  288. YBWeakSelf;
  289. //回调事件处理
  290. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  291. NSString *docDir = [paths objectAtIndex:0];
  292. NSString *loadPath = [docDir stringByAppendingFormat:@"/*%@*%@*%@*%@.mp3",model.musicNameStr,model.singerStr,model.timeStr,model.songID];
  293. cell.recordEvent = ^(NSString *type) {
  294. //停止播放音乐
  295. [weakSelf stopMusic];
  296. //开拍之前()---开拍之后(编辑页面)
  297. if ([_fromWhere isEqual:@"edit"]) {
  298. [self recoveryVolume];
  299. //回调音频路径
  300. if (weakSelf.pathEvent) {
  301. weakSelf.pathEvent(loadPath, model.songID);
  302. }
  303. [weakSelf dismissViewControllerAnimated:YES completion:nil];
  304. }else{
  305. TCVideoRecordViewController *videoRecord = [TCVideoRecordViewController new];
  306. videoRecord.musicPath = loadPath;
  307. videoRecord.musicID = model.songID;
  308. videoRecord.haveBGM = YES;
  309. YBNavigationController *nav = [[YBNavigationController alloc]initWithRootViewController:videoRecord];
  310. nav.navigationBarHidden = YES;
  311. nav.modalPresentationStyle = 0;
  312. [self presentViewController:nav animated:YES completion:nil];
  313. }
  314. };
  315. __weak MusicCell *weakCell = cell;
  316. cell.rsEvent = ^(NSString *rs, NSString *erro) {
  317. if ([rs isEqual:@"sucess"]) {
  318. [weakSelf stopMusic];
  319. [weakSelf playMusic:loadPath currentCell:weakCell currentIndex:indexPath];
  320. }else{
  321. [MBProgressHUD showPop:erro];
  322. }
  323. [[JCHATAlertViewWait ins] hidenAll];
  324. };
  325. cell.selectedBackgroundView = [[UIImageView alloc]initWithImage:[PublicObj getImgWithColor:SelCell_Col]];
  326. return cell;
  327. }
  328. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  329. [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
  330. MusicCell *cell = (MusicCell *)[tableView cellForRowAtIndexPath:indexPath];
  331. MusicModel *model = _models[indexPath.row];
  332. if (self.curRow == (int)indexPath.row) {
  333. self.curRow = -99999;
  334. self.isOpen = NO;
  335. [self stopMusic];
  336. [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  337. return;
  338. }else{
  339. self.isOpen = YES;
  340. }
  341. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  342. NSString *docDir = [paths objectAtIndex:0];
  343. NSString *loadPath = [docDir stringByAppendingFormat:@"/*%@*%@*%@*%@.mp3",model.musicNameStr,model.singerStr,model.timeStr,model.songID];
  344. NSFileManager *manager = [NSFileManager defaultManager];
  345. if ([manager fileExistsAtPath:loadPath]) {
  346. //已下载
  347. [self playMusic:loadPath currentCell:cell currentIndex:indexPath];
  348. }else{
  349. [[JCHATAlertViewWait ins] showInView];
  350. //下载歌曲
  351. [cell musicDownLoad];
  352. }
  353. //处理显示、隐藏开拍按钮
  354. if (self.curRow == (int)indexPath.row) {
  355. return;
  356. }
  357. MusicCell *lastCell = (MusicCell *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:self.curRow inSection:0]];
  358. [lastCell.StateBtn setImage:[UIImage imageNamed:@"music_play"] forState:0];
  359. self.isOpen = YES;
  360. self.curRow = (int)indexPath.row;
  361. /** 刷新tableView,系统默认会有一个自带的动画 */
  362. [tableView beginUpdates];
  363. //10-31添加
  364. lastCell.startRecoedBtn.hidden = YES;
  365. cell.startRecoedBtn.hidden = NO;
  366. //(self.curRow == (int)indexPath.row && self.isOpen) ? (cell.startRecoedBtn.hidden = NO) : (cell.startRecoedBtn.hidden = YES);
  367. [tableView endUpdates];
  368. }
  369. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  370. //普通cell 80 播放音乐+50
  371. return (self.curRow == (int)indexPath.row && self.isOpen) ? 130 : 80;
  372. }
  373. -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
  374. [self.search resignFirstResponder];
  375. }
  376. #pragma mark - 搜索关键词/清除关键词 更改分类以及tableview的高度
  377. -(void)reduceHeight {
  378. _musicClassV.frame = CGRectMake(0, _searchBg.bottom+5, _window_width, 0);
  379. _tableView.frame = CGRectMake(0,_musicClassV.bottom, _window_width, _window_height-64-statusbarHeight-ShowDiff-_searchBg.height-_musicClassV.height-5);
  380. }
  381. -(void)recoveryHeight {
  382. _musicClassV.frame = CGRectMake(0, _searchBg.bottom+5, _window_width, classHeight);
  383. _tableView.frame = CGRectMake(0,_musicClassV.bottom, _window_width, _window_height-64-statusbarHeight-ShowDiff-_searchBg.height-_musicClassV.height-5);
  384. }
  385. #pragma mark - 搜索框
  386. -(void)clickClearBtn {
  387. _isSearch = NO;
  388. [self recoveryHeight];
  389. if (_isColl == NO) {
  390. //重新加载热门
  391. [self pullTopTenMusic];
  392. }else{
  393. [self pullCollectMusic];
  394. }
  395. }
  396. -(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{
  397. }
  398. -(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
  399. //一个一个字清空搜索框的时候
  400. if (searchText.length==0) {
  401. _isSearch = NO;
  402. [self recoveryHeight];
  403. if (_isColl == NO) {
  404. //重新加载热门
  405. [self pullTopTenMusic];
  406. }else{
  407. [self pullCollectMusic];
  408. }
  409. }else{
  410. _isSearch = YES;
  411. }
  412. }
  413. -(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar{
  414. [searchBar resignFirstResponder];
  415. }
  416. -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
  417. _isSearch = YES;
  418. [self reduceHeight];
  419. //指示器显示
  420. [PublicView indictorShow];
  421. [searchBar resignFirstResponder];
  422. // self.allArray = nil;
  423. // self.allArray = [NSArray array];
  424. // [self.tableView reloadData];
  425. //重置部分属性
  426. [self resetAttribute];
  427. [self pullSearchMusic];
  428. }
  429. #pragma mark - set/get
  430. -(UIView *)searchBg {
  431. if (!_searchBg) {
  432. _searchBg = [[UIView alloc]initWithFrame:CGRectMake(0,64+statusbarHeight,_window_width,44)];
  433. _searchBg.backgroundColor = [UIColor whiteColor];
  434. _search = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0, _window_width,44)];
  435. _search.backgroundImage = [PublicObj getImgWithColor:[UIColor whiteColor]];
  436. _search.placeholder = YZMsg(@"搜索歌曲名称");
  437. _search.delegate = self;
  438. UITextField *textField ;
  439. if (@available(iOS 13.0,*)) {
  440. textField = _search.searchTextField;
  441. }else {
  442. textField = [_search valueForKey:@"_searchField"];
  443. }
  444. [textField setBackgroundColor:RGB_COLOR(@"#f9fafb", 1)];
  445. // [textField setValue:GrayText forKeyPath:@"_placeholderLabel.textColor"];
  446. // [textField setValue:[UIFont systemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];
  447. UIButton *clearBtn = [textField valueForKey:@"_clearButton"];
  448. [clearBtn addTarget:self action:@selector(clickClearBtn) forControlEvents:UIControlEventTouchUpInside];
  449. textField.textColor = GrayText;
  450. textField.layer.cornerRadius = 18;
  451. textField.layer.masksToBounds = YES;
  452. [_searchBg addSubview:_search];
  453. }
  454. return _searchBg;
  455. }
  456. - (MusicHeaderView *)musicClassV {
  457. if (!_musicClassV) {
  458. //5个像素空隙
  459. classHeight = _window_width/5.5+60;
  460. YBWeakSelf;
  461. _musicClassV = [[MusicHeaderView alloc]initWithFrame:CGRectMake(0, _searchBg.bottom+5, _window_width, classHeight) withBlock:^(NSString *type, NSString *title) {
  462. //停止播放音乐
  463. [weakSelf stopMusic];
  464. MusicClassVC *classVC = [[MusicClassVC alloc]init];
  465. classVC.navi_title = title;
  466. classVC.class_id = type;
  467. if ([_fromWhere isEqual:@"edit"]) {
  468. classVC.fromWhere = _fromWhere;
  469. }
  470. classVC.backEvent = ^(NSString *type, NSString *loadPath, NSString *songID) {
  471. [weakSelf recoveryVolume];
  472. //从音乐分类中返回事件
  473. if (weakSelf.pathEvent && [type isEqual:@"分类音乐"]) {
  474. weakSelf.pathEvent(loadPath, songID);
  475. }
  476. [weakSelf dismissViewControllerAnimated:YES completion:nil];
  477. };
  478. [weakSelf.navigationController pushViewController:classVC animated:YES];
  479. }];
  480. _musicClassV.segEvent = ^(NSString *type) {
  481. //重置部分属性
  482. [weakSelf resetAttribute];
  483. [weakSelf stopMusic];
  484. if ([type isEqual:@"热门"]) {
  485. _isColl = NO;
  486. [weakSelf pullTopTenMusic];
  487. }else{//收藏
  488. _isColl = YES;
  489. [weakSelf pullCollectMusic];
  490. }
  491. };
  492. }
  493. return _musicClassV;
  494. }
  495. - (UITableView *)tableView {
  496. if (!_tableView) {
  497. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,_musicClassV.bottom, _window_width, _window_height-64-statusbarHeight-ShowDiff-_searchBg.height-_musicClassV.height-5) style:UITableViewStylePlain];
  498. _tableView.dataSource = self;
  499. _tableView.delegate = self;
  500. _tableView.backgroundColor = [UIColor whiteColor];
  501. _tableView.separatorStyle = UITableViewCellAccessoryNone;
  502. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  503. _paging = 1;
  504. if (_isSearch == YES) {
  505. [self pullSearchMusic];
  506. }else{
  507. if (_isColl == YES) {
  508. [self pullCollectMusic];
  509. }else{
  510. [self pullTopTenMusic];
  511. }
  512. }
  513. }];
  514. _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  515. _paging +=1;
  516. if (_isSearch == YES) {
  517. [self pullSearchMusic];
  518. }else{
  519. if (_isColl == YES) {
  520. [self pullCollectMusic];
  521. }else{
  522. //top10没有分页
  523. _paging = 1;
  524. [self pullTopTenMusic];
  525. }
  526. }
  527. }];
  528. UISwipeGestureRecognizer *swip = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(keyHide)];
  529. swip.direction = UISwipeGestureRecognizerDirectionDown|UISwipeGestureRecognizerDirectionUp;
  530. [_tableView addGestureRecognizer:swip];
  531. }
  532. return _tableView;
  533. }
  534. #pragma mark - 导航
  535. -(void)creatNavi {
  536. UIView *navi = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, 64+statusbarHeight)];
  537. navi.backgroundColor = Normal_Color;
  538. [self.view addSubview:navi];
  539. UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, statusbarHeight+20,_window_width ,44)];
  540. bgView.backgroundColor = [UIColor whiteColor];
  541. [navi addSubview:bgView];
  542. UIBezierPath * maskPath = [UIBezierPath bezierPathWithRoundedRect:bgView.bounds byRoundingCorners:UIRectCornerTopRight|UIRectCornerTopLeft cornerRadii:CGSizeMake(5, 5)];
  543. CAShapeLayer * maskLayer = [[CAShapeLayer alloc]init];
  544. maskLayer.frame = bgView.bounds;
  545. maskLayer.path = maskPath.CGPath;
  546. bgView.layer.mask = maskLayer;
  547. UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  548. [leftBtn setImage:[UIImage imageNamed:@"gray_close"] forState:0];//pub_back
  549. leftBtn.frame = CGRectMake(0, 12+statusbarHeight, 50, 50);
  550. leftBtn.imageEdgeInsets = UIEdgeInsetsMake(20, 16, 12, 16);
  551. [leftBtn addTarget:self action:@selector(clickBackBtn) forControlEvents:UIControlEventTouchUpInside];
  552. [navi addSubview:leftBtn];
  553. CGFloat top_space = 22+statusbarHeight;
  554. if (IS_IPHONE_X) {
  555. top_space = 18+statusbarHeight;
  556. }
  557. UILabel *midL = [[UILabel alloc]initWithFrame:CGRectMake(50, top_space, _window_width-100, 40)];
  558. midL.text = YZMsg(@"选择音乐");
  559. midL.textColor = [UIColor blackColor];
  560. midL.font = SYS_Font(17);
  561. midL.textAlignment = NSTextAlignmentCenter;
  562. [navi addSubview:midL];
  563. }
  564. -(void)clickBackBtn {
  565. [self recoveryVolume];
  566. //停止播放音乐
  567. [self stopMusic];
  568. [self dismissViewControllerAnimated:YES completion:nil];
  569. [self.navigationController popViewControllerAnimated:YES];
  570. }
  571. -(void)dealloc{
  572. }
  573. @end