audioPlayerViewController.m 30 KB

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