audioPlayerViewController.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. //
  2. // audioPlayerViewController.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/5/26.
  6. //
  7. #import "audioPlayerViewController.h"
  8. #import "DFPlayer.h"
  9. #import "DFPlayerUIManager.h"
  10. #import "NASFileAudioModel.h"
  11. #import "lastFileManager.h"
  12. #import "audioPlayListManager.h"
  13. #import <QuartzCore/QuartzCore.h>
  14. #import "previewAudioPortraitTopMoreView.h"
  15. #import "editShareView.h"
  16. #import "uploadFileRecordViewController.h"
  17. #import "previewAudioPortraitDetailsView.h"
  18. #import "audioPlayListView.h"
  19. @interface audioPlayerViewController ()<DFPlayerDelegate,DFPlayerDataSource>
  20. @property (nonatomic, strong) UIImageView*bgImageView;//中间图片
  21. @property (nonatomic, strong) UIImageView*playImageView;//
  22. @property (nonatomic, strong) CABasicAnimation *rotationAnimation;
  23. @property (nonatomic, strong) UILabel *AudioTitleLab;//音乐标题
  24. @property (nonatomic, strong)UIButton * playPauseBtn;
  25. @property (nonatomic, strong)UIButton * playNextBtn;
  26. @property (nonatomic, strong)UIButton * playLastBtn;
  27. @property (nonatomic, strong)UIButton * playListBtn;//歌单
  28. @property (nonatomic, strong)UIButton * playModelBtn;//播放模式(单机 随机 循环)
  29. @property (nonatomic, strong) NSMutableArray<DFPlayerModel *> *dataArray;
  30. @property (nonatomic, assign) NSInteger lastAudioIndex;//-1未记录
  31. @property (nonatomic, strong) audioPlayListView *audioPlayListV;
  32. @end
  33. @implementation audioPlayerViewController
  34. - (void)viewDidLoad {
  35. [super viewDidLoad];
  36. // Do any additional setup after loading the view.
  37. [self.toolBar setHidden:YES];
  38. [self.navigationBar setHidden:YES];
  39. [self.navBarBGView setHidden:NO];
  40. self.navBarBGView.backgroundColor = [UIColor whiteColor];
  41. [self.view setBackgroundColor:[UIColor whiteColor]];
  42. [self drawAnyView];
  43. _lastAudioIndex = -1;
  44. }
  45. - (void)drawAnyView{
  46. _bgImageView = [UIImageView new];
  47. _bgImageView.image = [UIImage imageNamed:@"audioBgImg"];
  48. [self.view addSubview:_bgImageView];
  49. [_bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.top.equalTo(self.navBarBGView.mas_bottom).offset(90);
  51. make.width.mas_equalTo(200);
  52. make.height.mas_equalTo(200);
  53. make.centerX.mas_equalTo(0);
  54. }];
  55. _playImageView = [UIImageView new];
  56. _playImageView.image = [UIImage imageNamed:@"audioPlayImg"];
  57. [self.view addSubview:_playImageView];
  58. [_playImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  59. //make.top.equalTo(_bgImageView.mas_top).offset(-19);
  60. make.top.equalTo(_bgImageView.mas_top).offset(-19 - 85);
  61. make.width.mas_equalTo(110);
  62. make.height.mas_equalTo(170);
  63. //make.left.equalTo(_bgImageView.mas_right).offset(-60);
  64. make.left.equalTo(_bgImageView.mas_right).offset(-60 +55);
  65. }];
  66. [self setAnchorPoint:CGPointMake(1.0, 0.0) forView:_playImageView];
  67. _AudioTitleLab = [[UILabel alloc] init];
  68. _AudioTitleLab.textAlignment = NSTextAlignmentCenter;
  69. _AudioTitleLab.textColor = [UIColor blackColor];
  70. _AudioTitleLab.font = [UIFont systemFontOfSize:18.0];
  71. _AudioTitleLab.numberOfLines = 2;
  72. [self.view addSubview:_AudioTitleLab];
  73. [_AudioTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.top.equalTo(_bgImageView.mas_bottom).offset(15);
  75. make.left.mas_equalTo(30);
  76. make.right.mas_equalTo(-30);
  77. make.height.mas_equalTo(45);
  78. }];
  79. //底部UI背景
  80. UIImageView* bottombgImageView = [UIImageView new];
  81. bottombgImageView.image = [UIImage imageNamed:@"audioBottomBg"];
  82. bottombgImageView.userInteractionEnabled = YES;
  83. [self.view addSubview:bottombgImageView];
  84. CGFloat bottombgH = SCREEN_W*280.0/375.0;
  85. [bottombgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.bottom.mas_equalTo(0);
  87. make.left.mas_equalTo(0);
  88. make.right.mas_equalTo(0);
  89. make.height.mas_equalTo(bottombgH);
  90. }];
  91. [self initRightUpButtonFun];
  92. [self initDFPlayer];
  93. }
  94. #pragma mark 右上角按钮
  95. - (void)initRightUpButtonFun
  96. {
  97. //更多按钮
  98. UIButton *morenButton = [[UIButton alloc] init];
  99. [morenButton setImage:[UIImage imageNamed:@"nas_preview_more_black"] forState:UIControlStateNormal];
  100. morenButton.tag = 1;
  101. [morenButton addTarget:self action:@selector(didClickHeadButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  102. [self.view addSubview:morenButton];
  103. [morenButton mas_makeConstraints:^(MASConstraintMaker *make) {
  104. make.centerY.equalTo(self.titleLabel.mas_centerY).offset(0);
  105. make.right.mas_equalTo(-16);
  106. make.width.mas_equalTo(30);
  107. make.height.mas_equalTo(30);
  108. }];
  109. UIButton *shareButton = [[UIButton alloc] init];
  110. [shareButton setImage:[UIImage imageNamed:@"nas_preview_share_black"] forState:UIControlStateNormal];
  111. shareButton.tag = 2;
  112. [shareButton addTarget:self action:@selector(didClickHeadButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  113. [self.view addSubview:shareButton];
  114. [shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
  115. make.centerY.equalTo(self.titleLabel.mas_centerY).offset(0);
  116. make.right.equalTo(morenButton.mas_left).offset(-20);
  117. make.width.mas_equalTo(30);
  118. make.height.mas_equalTo(30);
  119. }];
  120. }
  121. #pragma mark - 以下代码与DFPlayer库有关
  122. #pragma mark - 初始化DFPlayer
  123. - (void)initDFPlayer{
  124. [[DFPlayer sharedPlayer] df_initPlayerWithUserId:nil];
  125. [DFPlayer sharedPlayer].dataSource = self;
  126. [DFPlayer sharedPlayer].delegate = self;
  127. [DFPlayer sharedPlayer].playMode = DFPlayerModeOrderCycle;
  128. [DFPlayer sharedPlayer].isObserveWWAN = NO;
  129. // [[DFPlayer sharedPlayer] df_reloadData];//需在传入数据源后调用
  130. UIImage *nextImage = [UIImage imageNamed:@"dfplayer_next"];
  131. UIImage *lastImage = [UIImage imageNamed:@"dfplayer_last"];
  132. UIImage *playImage = [UIImage imageNamed:@"dfplayer_play"];
  133. UIImage *pauseImage = [UIImage imageNamed:@"dfplayer_pause"];
  134. UIImage *ovalImage = [UIImage imageNamed:@"dfplayer_oval"];
  135. DFPlayerUIManager *mgr = [DFPlayerUIManager sharedManager];
  136. //缓冲条
  137. // [mgr df_bufferViewWithFrame:CGRectZero
  138. // trackTintColor:[[UIColor lightGrayColor] colorWithAlphaComponent:0.5]
  139. // progressTintColor:[UIColor colorWithWhite:1 alpha:0.5]
  140. // superView:self.view];
  141. //播放暂停按钮
  142. //_playPauseBtn = [mgr df_playPauseBtnWithFrame:CGRectZero playImage:playImage pauseImage:pauseImage superView:self.view block:nil];
  143. _playPauseBtn = [[UIButton alloc] init];
  144. [_playPauseBtn setImage:playImage forState:UIControlStateSelected];
  145. [_playPauseBtn setImage:pauseImage forState:UIControlStateNormal];
  146. [_playPauseBtn addTarget:self action:@selector(playOrPauseButtonDidClickFun:) forControlEvents:UIControlEventTouchUpInside];
  147. [self.view addSubview:_playPauseBtn];
  148. _playPauseBtn.selected = YES;
  149. [_playPauseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  150. make.bottom.mas_equalTo(-54);
  151. make.height.mas_equalTo(32);
  152. make.width.mas_equalTo(32);
  153. make.centerX.mas_equalTo(0);
  154. }];
  155. //下一首按钮
  156. _playNextBtn = [mgr df_nextBtnWithFrame:CGRectZero image:nextImage superView:self.view block:nil];
  157. [_playNextBtn setImage:[UIImage imageNamed:@"dfplayer_next_none"] forState:UIControlStateDisabled];
  158. [_playNextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  159. make.centerY.equalTo(_playPauseBtn.mas_centerY).offset(0);
  160. make.height.mas_equalTo(32);
  161. make.width.mas_equalTo(32);
  162. make.left.equalTo(_playPauseBtn.mas_right).offset(50);
  163. }];
  164. //上一首按钮
  165. _playLastBtn = [mgr df_lastBtnWithFrame:CGRectZero image:lastImage superView:self.view block:nil];
  166. [_playLastBtn setImage:[UIImage imageNamed:@"dfplayer_last_none"] forState:UIControlStateDisabled];
  167. [_playLastBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  168. make.centerY.equalTo(_playPauseBtn.mas_centerY).offset(0);
  169. make.height.mas_equalTo(32);
  170. make.width.mas_equalTo(32);
  171. make.right.equalTo(_playPauseBtn.mas_left).offset(-50);
  172. }];
  173. //歌单
  174. _playListBtn = [[UIButton alloc] init];
  175. [_playListBtn setImage:[UIImage imageNamed:@"dfplayer_playlist"] forState:UIControlStateNormal];
  176. [_playListBtn addTarget:self action:@selector(didClickPlayListFun) forControlEvents:UIControlEventTouchUpInside];
  177. [self.view addSubview:_playListBtn];
  178. [_playListBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  179. make.centerY.equalTo(_playPauseBtn.mas_centerY).offset(0);
  180. make.height.mas_equalTo(25);
  181. make.width.mas_equalTo(25);
  182. //make.left.equalTo(_playNextBtn.mas_right).offset(50);
  183. make.right.mas_equalTo(-20);
  184. }];
  185. // //播放模式按钮
  186. // [mgr df_typeBtnWithFrame:typeRect singleImage:singleImage circleImage:circleImage shuffleImage:shuffleImage superView:_bgView block:nil];
  187. //播放模型
  188. _playModelBtn = [[UIButton alloc] init];
  189. [_playModelBtn setImage:[UIImage imageNamed:@"dfplayer_circle"] forState:UIControlStateNormal];
  190. [_playModelBtn addTarget:self action:@selector(didClickPlayModelButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  191. [self.view addSubview:_playModelBtn];
  192. [_playModelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  193. make.centerY.equalTo(_playPauseBtn.mas_centerY).offset(0);
  194. make.height.mas_equalTo(25);
  195. make.width.mas_equalTo(25);
  196. make.left.mas_equalTo(20);
  197. }];
  198. //进度条
  199. UISlider * curSlider = [mgr df_sliderWithFrame:CGRectZero
  200. minimumTrackTintColor:[UIColor hwColor:@"#0CDEFD"]
  201. maximumTrackTintColor:[UIColor hwColor:@"#E3E3E3"]
  202. trackHeight:4
  203. thumbImage:[ovalImage imageByResizeToSize:(CGSize){15,14}]
  204. superView:self.view];
  205. [curSlider mas_makeConstraints:^(MASConstraintMaker *make) {
  206. make.bottom.equalTo(_playPauseBtn.mas_top).offset(-40);
  207. make.height.mas_equalTo(40);
  208. make.left.mas_equalTo(70);
  209. make.right.mas_equalTo(-70);
  210. }];
  211. //当前时间
  212. UILabel *currentTimeLabel =[mgr df_currentTimeLabelWithFrame:CGRectZero
  213. textColor:[UIColor hwColor:@"#999999"]
  214. textAlignment:(NSTextAlignmentCenter)
  215. font:[UIFont systemFontOfSize:14.0]
  216. superView:self.view];
  217. [currentTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  218. make.top.equalTo(curSlider.mas_top).offset(0);
  219. make.height.mas_equalTo(40);
  220. make.left.mas_equalTo(5);
  221. make.right.equalTo(curSlider.mas_left).offset(-5);
  222. }];
  223. //总时间
  224. UILabel *totalTimeLabel = [mgr df_totalTimeLabelWithFrame:CGRectZero
  225. textColor:[UIColor hwColor:@"#999999"]
  226. textAlignment:(NSTextAlignmentCenter)
  227. font:[UIFont systemFontOfSize:14.0]
  228. superView:self.view];
  229. [totalTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  230. make.top.equalTo(curSlider.mas_top).offset(0);
  231. make.height.mas_equalTo(40);
  232. make.right.mas_equalTo(-5);
  233. make.left.equalTo(curSlider.mas_right).offset(5);
  234. }];
  235. }
  236. #pragma mark 开始和暂停 按钮点击时间
  237. - (void)playOrPauseButtonDidClickFun:(UIButton*)but
  238. {
  239. but.selected = !but.selected;
  240. if(but.selected){
  241. [self startRotatingImage];
  242. [self startPlayingRotateRightImage];
  243. [[DFPlayer sharedPlayer] df_play];
  244. }
  245. else{
  246. [self stopRotatingImage];
  247. [self stopPlayingRotateRightImage];
  248. [[DFPlayer sharedPlayer] df_pause];
  249. }
  250. }
  251. #pragma mark 开始和暂停 按钮点击时间
  252. - (void)didClickPlayModelButtonFun:(UIButton*)but
  253. {
  254. switch ([DFPlayer sharedPlayer].playMode) {
  255. case DFPlayerModeSingleCycle://单曲循环->顺序循环
  256. [DFPlayer sharedPlayer].playMode = DFPlayerModeOrderCycle;
  257. [but setImage:[UIImage imageNamed:@"dfplayer_circle"] forState:UIControlStateNormal];
  258. [[iToast makeText:NSLocalizedString(@"NAS_audio_playModel_circle",nil)] show];
  259. break;
  260. case DFPlayerModeOrderCycle://顺序循环->随机循环
  261. [DFPlayer sharedPlayer].playMode = DFPlayerModeShuffleCycle;
  262. [but setImage:[UIImage imageNamed:@"dfplayer_shuffle"] forState:UIControlStateNormal];
  263. [[iToast makeText:NSLocalizedString(@"NAS_audio_playModel_shuffle",nil)] show];
  264. break;
  265. case DFPlayerModeShuffleCycle://随机循环->单曲循环
  266. [DFPlayer sharedPlayer].playMode = DFPlayerModeSingleCycle;
  267. [but setImage:[UIImage imageNamed:@"dfplayer_single"] forState:UIControlStateNormal];
  268. [[iToast makeText:NSLocalizedString(@"NAS_audio_playModel_single",nil)] show];
  269. break;
  270. default:
  271. break;
  272. }
  273. }
  274. #pragma mark 点击右上角 更多或分享
  275. - (void)didClickHeadButtonFun:(UIButton*)but
  276. {
  277. NSInteger tag = but.tag;
  278. if(tag == 1){
  279. previewAudioPortraitTopMoreView *topMoreV = [[previewAudioPortraitTopMoreView alloc] init];
  280. [self.view addSubview:topMoreV];
  281. [topMoreV mas_makeConstraints:^(MASConstraintMaker *make) {
  282. make.top.mas_equalTo(0);
  283. make.bottom.mas_equalTo(0);
  284. make.right.mas_equalTo(0);
  285. make.left.mas_equalTo(0);
  286. }];
  287. KWeakSelf
  288. topMoreV.didClickButtonFun = ^(NSInteger tag) {
  289. switch (tag) {
  290. case 10:
  291. [weakSelf gotoDownLoadFileFun];
  292. break;
  293. case 11:
  294. [weakSelf showDeleteAlearViewFun];
  295. break;
  296. case 12:
  297. [weakSelf didClickDetailsFun];
  298. break;
  299. default:
  300. break;
  301. }
  302. };
  303. }
  304. else if (tag == 2){
  305. [self gotoShareViewFun];
  306. }
  307. }
  308. #pragma mark 用户点击分享
  309. - (void)gotoShareViewFun
  310. {
  311. editShareView *editShareV = [[editShareView alloc] init];
  312. NASFileAudioDataModel *dataModel = _audioOutSidedataArray[_index];
  313. editShareV.didSelectListArr = [NSMutableArray arrayWithArray:@[dataModel]];
  314. editShareV.shareFileType = @"4";
  315. [self.view addSubview:editShareV];
  316. [editShareV mas_makeConstraints:^(MASConstraintMaker *make) {
  317. make.left.mas_equalTo(0);
  318. make.right.mas_equalTo(0);
  319. make.bottom.mas_equalTo(0);
  320. make.top.mas_equalTo(0);
  321. }];
  322. }
  323. #pragma mark 用户点击下载
  324. - (void)gotoDownLoadFileFun
  325. {
  326. NASFileAudioDataModel *dataModel = _audioOutSidedataArray[_index];
  327. couldPhoneFileModel* fileModel = [couldPhoneFileModel new];
  328. fileModel.fileType = @"audio";
  329. fileModel.path = dataModel.path;
  330. fileModel.name = dataModel.name;
  331. fileModel.length = dataModel.size;
  332. NSMutableArray *arr = [NSMutableArray new];
  333. [arr addObject:fileModel];
  334. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  335. [self.navigationController pushViewController:vc animated:YES];
  336. vc.isDownloadingType = YES;
  337. [vc gotoDownloadFile:arr];
  338. }
  339. #pragma mark 用户点击删除
  340. - (void)showDeleteAlearViewFun
  341. {
  342. NSString *titleStr = NSLocalizedString(@"delete_file_title_msg",nil);
  343. NSString *tipStr = NSLocalizedString(@"delete_file_tip_msg",nil);
  344. KWeakSelf
  345. ComontAlretViewController *curAlretVC= [[ComontAlretViewController alloc] initWithTiTle:titleStr
  346. msg:tipStr
  347. imageStr:nil
  348. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  349. okTitle:NSLocalizedString(@"other_confirm",nil) isOkBtnHighlight:YES
  350. didClickOk:^{
  351. [weakSelf delFileListFun];
  352. } didClickCancel:^{
  353. }];
  354. curAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  355. [self presentViewController:curAlretVC animated:YES completion:^{
  356. curAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  357. }];
  358. }
  359. #pragma mark 删除文件数据
  360. - (void)delFileListFun
  361. {
  362. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  363. NSMutableArray *pathArr = [NSMutableArray new];
  364. NASFileAudioDataModel *dataModel = _audioOutSidedataArray[_index];
  365. [pathArr addObject:dataModel.path];
  366. [paraDict setValue:pathArr forKey:@"path"];
  367. [self showNewIndicatorWithCanBack:YES canTouch:NO];
  368. //NSString*code = [[NSString alloc] initWithFormat:@"delFile?path=%@",paraDict[@"path"]]; //delFile?path=[/storage/emulated/0/Download/IMG_6464.HEIC]
  369. KWeakSelf //@"delFile"
  370. [[netWorkManager shareInstance] cloudPhonePostCallBackCode:@"delFile" Parameters:paraDict success:^(id _Nonnull responseObject) {
  371. [weakSelf removeNewIndicator];
  372. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  373. if(model && model.status == 0){
  374. [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show];
  375. [weakSelf didDeleteSucFun:dataModel.path];
  376. }
  377. else{
  378. }
  379. } failure:^(NSError * _Nonnull error) {
  380. [weakSelf removeNewIndicator];
  381. }];
  382. }
  383. #pragma mark 删除成功
  384. - (void)didDeleteSucFun:(NSString*)path
  385. {
  386. //1.删除最近文件数据
  387. [[lastFileManager shareManager] deleteFileInfoWithUrl:path];
  388. [[audioPlayListManager shareManager] deleteFileInfoWithUrl:path];
  389. if(_didNeedToRegetDataFun){
  390. _didNeedToRegetDataFun();
  391. }
  392. [self.navigationController popViewControllerAnimated:YES];
  393. }
  394. #pragma mark 用户点击详情
  395. - (void)didClickDetailsFun
  396. {
  397. NSMutableArray *pathArr = [NSMutableArray new];
  398. NASFileAudioDataModel *dataModel = _audioOutSidedataArray[_index];
  399. previewAudioPortraitDetailsView *topDetailsV = [[previewAudioPortraitDetailsView alloc] initWithFrame:CGRectZero withData:dataModel];
  400. [self.view addSubview:topDetailsV];
  401. [topDetailsV mas_makeConstraints:^(MASConstraintMaker *make) {
  402. make.top.mas_equalTo(0);
  403. make.bottom.mas_equalTo(0);
  404. make.right.mas_equalTo(0);
  405. make.left.mas_equalTo(0);
  406. }];
  407. }
  408. #pragma mark 用户点击播放列表
  409. - (void)didClickPlayListFun
  410. {
  411. _audioPlayListV = [[audioPlayListView alloc] initWithFrame:CGRectZero withIndex:_index];
  412. [self.view addSubview:_audioPlayListV];
  413. [_audioPlayListV mas_makeConstraints:^(MASConstraintMaker *make) {
  414. make.top.mas_equalTo(0);
  415. make.bottom.mas_equalTo(0);
  416. make.right.mas_equalTo(0);
  417. make.left.mas_equalTo(0);
  418. }];
  419. }
  420. #pragma mark - DFPLayer dataSource
  421. - (NSArray<DFPlayerModel *> *)df_audioDataForPlayer:(DFPlayer *)player{
  422. _dataArray = [NSMutableArray array];
  423. for (int i = 0; i < _audioOutSidedataArray.count; i++) {
  424. NASFileAudioDataModel *yourModel = _audioOutSidedataArray[i];
  425. DFPlayerModel *model = [[DFPlayerModel alloc] init];
  426. model.audioId = i;//****重要。AudioId从0开始,仅标识当前音频在数组中的位置。
  427. NSString *filePath = yourModel.path;
  428. NSString *urlStr = ksharedAppDelegate.NASFileByBoxService;
  429. NSString *string = filePath;
  430. NSString *filePathBase64 = [iTools base64UrlEncoder:string];
  431. // NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
  432. // NSString *filePathBase64 = [data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
  433. // NSData *data2 = [[NSData alloc] initWithBase64EncodedString:filePathBase64 options:NSDataBase64DecodingIgnoreUnknownCharacters];
  434. //
  435. // NSString *string32 =[[NSString alloc] initWithData:data2 encoding:NSUTF8StringEncoding];
  436. // HLog(@"hxd1111: %@",string32);
  437. //filePath = [filePath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  438. //NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,filePath];
  439. //NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getFiles?path=%@",urlStr,filePath];
  440. NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getFiles/%@",urlStr,filePathBase64];
  441. HLog(@"hxd2222:%@",fileUrl);
  442. //fileUrl = @"http://transfertest.armclouding.com:10006/getFile?path=/storage/emulated/0/Download/录音大师-2024.05.22-16:57.mp3";
  443. //fileUrl = @"http://m10.music.126.net/20240527160012/d3f165dc686ac01afd4497400b2c2c58/ymusic/5353/0f0f/0358/d99739615f8e5153d77042092f07fd77.mp3";
  444. //fileUrl = @"https://www.cambridgeenglish.org/images/153149-movers-sample-listening-test-vol2.mp3";
  445. //fileUrl = @"https://www.cambridgeenglish.org/images/506891-a2-key-for-schools-listening-sample-test.mp3";
  446. //fileUrl = @"http://downsc.chinaz.net/Files/DownLoad/sound1/201906/11582.mp3";
  447. //fileUrl = @"http://downsc.chinaz.net/files/download/sound1/201206/1638.mp3";
  448. //fileUrl =@"http://192.168.11.248:9888/getFile?path=/storage/C47D-46D2/audioTest/jiajiaeeyinyue.mp3";
  449. //fileUrl =@"http://transfertest.armclouding.com:21025/getFiles/L3N0b3JhZ2UvZW11bGF0ZWQvMC9NdXNpYy9hYmMubXAz";
  450. //fileUrl = @"http://downsc.chinaz.net/files/download/sound1/201206/1638.mp3";
  451. //fileUrl = @"http://transfertest.armclouding.com:21025/test/abc/abc.mp3";
  452. //fileUrl = @"http://transfertest.armclouding.com:21025/test/abc/obj.mp3"; //0603 16:40验证可以播放
  453. //fileUrl = @"http://file.phone.androidscloud.com:8210/document/newFile/download/1/ikIm5C0KjKNvusTF6tIH/LowLevelMultipartUpload_44933618366140107699/1.mp3";
  454. // fileUrl = @"http://transfertest.armclouding.com:10001/getFile?path=/storage/6C07-E638/miniType/%E9%9F%B3%E9%A2%91%E6%A0%BC%E5%BC%8Fing/jiajiaeeyinyue.mp3";
  455. //fileUrl = @"http://transfertest.armclouding.com:21025/getFiles/L3N0b3JhZ2UvZW11bGF0ZWQvMC9NdXNpYy9vYmoubXAz";
  456. //fileUrl = @"http://transfertest.armclouding.com:21025/getFiles/L3NkY2FyZC9NdXNpYy9vYmoubXAz";
  457. //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/25883214_yinyue.wma";//不支持此媒体的格式
  458. //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/ffgfge.m4a";//可以播放
  459. //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/j14_yinyue.ogg";//不支持此媒体的格式
  460. // fileUrl = [fileUrl stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  461. NSURL * curURL = [NSURL fileURLWithPath:fileUrl];
  462. HLog(@"%@",curURL.absoluteString);
  463. model.audioUrl = curURL;
  464. // if ([yourModel.yourUrl hasPrefix:@"http"]) {//网络音频
  465. // model.audioUrl = [self getAvailableURL:yourModel.yourUrl];
  466. // }else{//本地音频
  467. // NSString *path = [[NSBundle mainBundle] pathForResource:yourModel.yourUrl ofType:@""];
  468. // if (path) {
  469. // model.audioUrl = [NSURL fileURLWithPath:path];
  470. // }
  471. // }
  472. [_dataArray addObject:model];
  473. }
  474. HLog(@"%@ --- %ld",_dataArray,_dataArray.count);
  475. return [_dataArray copy];
  476. }
  477. - (DFPlayerInfoModel *)df_audioInfoForPlayer:(DFPlayer *)player{
  478. DFPlayerInfoModel *infoModel = [[DFPlayerInfoModel alloc] init];
  479. // infoModel.audioName = @"";//yourModel.yourName;
  480. // infoModel.audioSinger = @"";//yourModel.yourSinger;
  481. // infoModel.audioAlbum = @"";//yourModel.yourAlbum;
  482. // infoModel.audioLyrics = @"";//[NSString stringWithContentsOfFile:lyricPath encoding:NSUTF8StringEncoding error:nil];
  483. //infoModel.audioImage = [UIImage imageWithData:imageData];
  484. return infoModel;
  485. }
  486. #pragma mark - DFPlayer delegate
  487. //加入播放队列
  488. - (void)df_playerAudioAddToPlayQueue:(DFPlayer *)player{
  489. // [self tableViewReloadData];
  490. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  491. // dispatch_async(dispatch_get_main_queue(), ^{
  492. // self.navigationItem.title = player.currentAudioInfoModel.audioName;
  493. // self->_bgView.image = [self getBackgroundImage:player.currentAudioInfoModel.audioImage];
  494. // self->_noticeLabel.text = player.currentAudioInfoModel.audioLyrics ? @"" : @"无可用歌词";
  495. // });
  496. // });
  497. }
  498. //缓冲进度代理
  499. - (void)df_player:(DFPlayer *)player bufferProgress:(CGFloat)bufferProgress{
  500. HLog(@"缓冲进度代理:%f",bufferProgress);
  501. }
  502. //播放进度代理
  503. - (void)df_player:(DFPlayer *)player progress:(CGFloat)progress currentTime:(CGFloat)currentTime{
  504. HLog(@"音频播放进度:%f --- %f",progress,currentTime);
  505. if(_lastAudioIndex != player.currentAudioModel.audioId){
  506. _lastAudioIndex = player.currentAudioModel.audioId;
  507. _index = _lastAudioIndex;
  508. [self setTitleFunByIndex];
  509. [self audioPlayerByIndex:_lastAudioIndex];
  510. [self startRotatingImage];
  511. [self startPlayingRotateRightImage];
  512. }
  513. if(progress >= 1.0){
  514. _lastAudioIndex = -1;
  515. [self stopRotatingImage];
  516. }
  517. }
  518. //状态信息代理
  519. - (void)df_player:(DFPlayer *)player didGetStatusCode:(DFPlayerStatusCode)statusCode{
  520. if (statusCode == DFPlayerStatusNoNetwork) {
  521. //[self showAlert:@"没有网络连接"];
  522. }else if(statusCode == DFPlayerStatusViaWWAN){
  523. // [self showAlert:@"继续播放将产生流量费用" okBlock:^{
  524. // [DFPlayer sharedPlayer].isObserveWWAN = NO;
  525. // [[DFPlayer sharedPlayer] df_playWithAudioId:player.currentAudioModel.audioId];
  526. // }];
  527. [DFPlayer sharedPlayer].isObserveWWAN = NO;
  528. [[DFPlayer sharedPlayer] df_playWithAudioId:player.currentAudioModel.audioId];
  529. }else if(statusCode == DFPlayerStatusTimeOut){
  530. //[self showAlert:@"请求超时"];
  531. }else if(statusCode == DFPlayerStatusCacheSucc){
  532. [[DFPlayer sharedPlayer] df_playWithAudioId:player.currentAudioModel.audioId];
  533. }else{
  534. HLog(@"状态码:%lu",(unsigned long)statusCode);
  535. [[iToast makeText:NSLocalizedString(@"play_video_fail_tip",nil)] show];
  536. [[DFPlayer sharedPlayer] df_next];
  537. }
  538. }
  539. - (void)viewDidAppear:(BOOL)animated
  540. {
  541. [super viewDidAppear:animated];
  542. [self setTitleFunByIndex];
  543. [[DFPlayer sharedPlayer] df_reloadData];//需在传入数据源后调用
  544. [DFPlayer sharedPlayer].playMode = DFPlayerModeOrderCycle;
  545. KWeakSelf
  546. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  547. [weakSelf playAudioFun];
  548. });
  549. }
  550. - (void)viewDidDisappear:(BOOL)animated
  551. {
  552. [super viewDidDisappear:animated];
  553. //[[DFPlayer sharedPlayer] df_deallocPlayer];
  554. }
  555. -(void)setTitleFunByIndex
  556. {
  557. if(_index < _audioOutSidedataArray.count){
  558. NASFileAudioDataModel* dataModel = _audioOutSidedataArray[_index];
  559. //self.titleLabel.text = dataModel.name;
  560. _AudioTitleLab.text = dataModel.name;
  561. if(_audioPlayListV){
  562. _audioPlayListV.playingIndex = _index;
  563. }
  564. }
  565. }
  566. - (void)playAudioFun
  567. {
  568. if(_index < self.dataArray.count){
  569. DFPlayerModel *model = self.dataArray[_index];
  570. [[DFPlayer sharedPlayer] df_playWithAudioId:model.audioId];
  571. }
  572. }
  573. #pragma mark 音频可以播放
  574. - (void)audioPlayerByIndex:(NSInteger)index{
  575. if(index >=0 && index < _audioOutSidedataArray.count){
  576. NASFileAudioDataModel *dataModel = _audioOutSidedataArray[index];
  577. lastFileModel *lastFileMod = [lastFileModel new];
  578. lastFileMod.path = dataModel.path;
  579. lastFileMod.name = dataModel.name;
  580. lastFileMod.time = dataModel.time;
  581. lastFileMod.size = dataModel.size;
  582. lastFileMod.duration = dataModel.duration;
  583. lastFileMod.type = @"audio";
  584. lastFileMod.lastPreTime = [iTools getNowTimeStamp];
  585. [[lastFileManager shareManager] saveFileInfoWith:lastFileMod with:dataModel.path];
  586. [[audioPlayListManager shareManager] saveFileInfoWith:lastFileMod with:dataModel.path];
  587. }
  588. }
  589. #pragma mark 图片旋转相关
  590. - (void)startRotatingImage {
  591. // 停止当前动画(如果有的话)
  592. [self stopRotatingImage];
  593. // 创建一个CABasicAnimation实例
  594. self.rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
  595. // 设置动画的起始值(从0度开始)
  596. self.rotationAnimation.fromValue = [NSNumber numberWithFloat:0];
  597. // 设置动画的结束值(旋转360度,注意这里是弧度制)
  598. self.rotationAnimation.toValue = [NSNumber numberWithFloat:M_PI * 2];
  599. // 设置动画的持续时间
  600. self.rotationAnimation.duration = 5.0; // 可以根据需要调整旋转速度
  601. // 设置动画的重复次数,这里设置为HUGE_VALF表示无限次
  602. self.rotationAnimation.repeatCount = HUGE_VALF;
  603. // 将动画添加到imageView的layer上
  604. [self.bgImageView.layer addAnimation:self.rotationAnimation forKey:@"rotateAnimation"];
  605. }
  606. - (void)stopRotatingImage {
  607. // 移除imageView上的动画
  608. [self.bgImageView.layer removeAnimationForKey:@"rotateAnimation"];
  609. [UIView animateWithDuration:5 animations:^{
  610. self.bgImageView.layer.transform = CATransform3DIdentity;
  611. }];
  612. }
  613. - (void)restartRotatingImage {
  614. // 直接调用startRotatingImage来重新启动动画
  615. [self startRotatingImage];
  616. }
  617. - (void)startPlayingRotateRightImage
  618. {
  619. [UIView animateWithDuration:2 animations:^{
  620. self.playImageView.transform = CGAffineTransformMakeRotation(0);
  621. //self.playImageView.transform = CGAffineTransformRotate(self.playImageView.transform, -M_PI / 6); // 逆时针旋转30度
  622. }];
  623. }
  624. - (void)stopPlayingRotateRightImage
  625. {
  626. [UIView animateWithDuration:2 animations:^{
  627. self.playImageView.transform = CGAffineTransformMakeRotation(-M_PI*0.15);
  628. }];
  629. }
  630. //改变旋转中心???
  631. - (void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view
  632. {
  633. CGPoint oldOrigin = view.frame.origin;
  634. view.layer.anchorPoint = anchorPoint;
  635. CGPoint newOrigin = view.frame.origin;
  636. CGPoint transition;
  637. transition.x = newOrigin.x - oldOrigin.x;
  638. transition.y = newOrigin.y - oldOrigin.y;
  639. view.center = CGPointMake (view.center.x - transition.x, view.center.y - transition.y);
  640. }
  641. @end