// // audioPlayerViewController.m // 双子星云手机 // // Created by xd h on 2024/5/26. // #import "audioPlayerViewController.h" #import "DFPlayer.h" #import "DFPlayerUIManager.h" #import "lastFileManager.h" #import "audioPlayListManager.h" #import #import "previewAudioPortraitTopMoreView.h" #import "editShareView.h" #import "uploadFileRecordViewController.h" #import "previewAudioPortraitDetailsView.h" #import "audioPlayListView.h" #import "addAudioToPlayListViewController.h" @interface audioPlayerViewController () @property (nonatomic, strong) UIImageView*bgImageView;//中间图片 @property (nonatomic, strong) UIImageView*playImageView;// @property (nonatomic, strong) CABasicAnimation *rotationAnimation; @property (nonatomic, strong) UILabel *AudioTitleLab;//音乐标题 @property (nonatomic, strong)UIButton * playPauseBtn; @property (nonatomic, strong)UIButton * playNextBtn; @property (nonatomic, strong)UIButton * playLastBtn; @property (nonatomic, strong)UIButton * playListBtn;//歌单 @property (nonatomic, strong)UIButton * playModelBtn;//播放模式(单机 随机 循环) @property (nonatomic, assign) NSInteger index;//当前位置 @property (nonatomic, strong) NSMutableArray * allAudioDataArray;//所有的 播放数据(NASFileAudioDataModel或者lastFileModel) @property (nonatomic, strong) NSMutableArray *dataArray; @property (nonatomic, assign) NSInteger lastAudioIndex;//-1未记录 @property (nonatomic, strong) audioPlayListView *audioPlayListV; @end @implementation audioPlayerViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self.toolBar setHidden:YES]; [self.navigationBar setHidden:YES]; [self.navBarBGView setHidden:NO]; self.navBarBGView.backgroundColor = [UIColor whiteColor]; [self.view setBackgroundColor:[UIColor whiteColor]]; [self drawAnyView]; _lastAudioIndex = -1; } - (void)drawAnyView{ _bgImageView = [UIImageView new]; _bgImageView.image = [UIImage imageNamed:@"audioBgImg"]; [self.view addSubview:_bgImageView]; [_bgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.navBarBGView.mas_bottom).offset(90); make.width.mas_equalTo(200); make.height.mas_equalTo(200); make.centerX.mas_equalTo(0); }]; _playImageView = [UIImageView new]; _playImageView.image = [UIImage imageNamed:@"audioPlayImg"]; [self.view addSubview:_playImageView]; [_playImageView mas_makeConstraints:^(MASConstraintMaker *make) { //make.top.equalTo(_bgImageView.mas_top).offset(-19); make.top.equalTo(_bgImageView.mas_top).offset(-19 - 85); make.width.mas_equalTo(110); make.height.mas_equalTo(170); //make.left.equalTo(_bgImageView.mas_right).offset(-60); make.left.equalTo(_bgImageView.mas_right).offset(-60 +55); }]; [self setAnchorPoint:CGPointMake(1.0, 0.0) forView:_playImageView]; _AudioTitleLab = [[UILabel alloc] init]; _AudioTitleLab.textAlignment = NSTextAlignmentCenter; _AudioTitleLab.textColor = [UIColor blackColor]; _AudioTitleLab.font = [UIFont systemFontOfSize:18.0]; _AudioTitleLab.numberOfLines = 2; [self.view addSubview:_AudioTitleLab]; [_AudioTitleLab mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(_bgImageView.mas_bottom).offset(15); make.left.mas_equalTo(30); make.right.mas_equalTo(-30); make.height.mas_equalTo(45); }]; //底部UI背景 UIImageView* bottombgImageView = [UIImageView new]; bottombgImageView.image = [UIImage imageNamed:@"audioBottomBg"]; bottombgImageView.userInteractionEnabled = YES; [self.view addSubview:bottombgImageView]; CGFloat bottombgH = SCREEN_W*280.0/375.0; [bottombgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.mas_equalTo(0); make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.height.mas_equalTo(bottombgH); }]; [self initRightUpButtonFun]; [self initDFPlayer]; } #pragma mark 右上角按钮 - (void)initRightUpButtonFun { //更多按钮 UIButton *morenButton = [[UIButton alloc] init]; [morenButton setImage:[UIImage imageNamed:@"nas_preview_more_black"] forState:UIControlStateNormal]; morenButton.tag = 1; [morenButton addTarget:self action:@selector(didClickHeadButtonFun:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:morenButton]; [morenButton mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.titleLabel.mas_centerY).offset(0); make.right.mas_equalTo(-16); make.width.mas_equalTo(30); make.height.mas_equalTo(30); }]; UIButton *shareButton = [[UIButton alloc] init]; [shareButton setImage:[UIImage imageNamed:@"nas_preview_share_black"] forState:UIControlStateNormal]; shareButton.tag = 2; [shareButton addTarget:self action:@selector(didClickHeadButtonFun:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:shareButton]; [shareButton mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.titleLabel.mas_centerY).offset(0); make.right.equalTo(morenButton.mas_left).offset(-20); make.width.mas_equalTo(30); make.height.mas_equalTo(30); }]; } #pragma mark - 以下代码与DFPlayer库有关 #pragma mark - 初始化DFPlayer - (void)initDFPlayer{ [[DFPlayer sharedPlayer] df_initPlayerWithUserId:nil]; [DFPlayer sharedPlayer].dataSource = self; [DFPlayer sharedPlayer].delegate = self; [DFPlayer sharedPlayer].playMode = DFPlayerModeOrderCycle; [DFPlayer sharedPlayer].isObserveWWAN = NO; // [[DFPlayer sharedPlayer] df_reloadData];//需在传入数据源后调用 UIImage *nextImage = [UIImage imageNamed:@"dfplayer_next"]; UIImage *lastImage = [UIImage imageNamed:@"dfplayer_last"]; UIImage *playImage = [UIImage imageNamed:@"dfplayer_play"]; UIImage *pauseImage = [UIImage imageNamed:@"dfplayer_pause"]; UIImage *ovalImage = [UIImage imageNamed:@"dfplayer_oval"]; DFPlayerUIManager *mgr = [DFPlayerUIManager sharedManager]; //缓冲条 // [mgr df_bufferViewWithFrame:CGRectZero // trackTintColor:[[UIColor lightGrayColor] colorWithAlphaComponent:0.5] // progressTintColor:[UIColor colorWithWhite:1 alpha:0.5] // superView:self.view]; //播放暂停按钮 //_playPauseBtn = [mgr df_playPauseBtnWithFrame:CGRectZero playImage:playImage pauseImage:pauseImage superView:self.view block:nil]; _playPauseBtn = [[UIButton alloc] init]; [_playPauseBtn setImage:playImage forState:UIControlStateSelected]; [_playPauseBtn setImage:pauseImage forState:UIControlStateNormal]; [_playPauseBtn addTarget:self action:@selector(playOrPauseButtonDidClickFun:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:_playPauseBtn]; _playPauseBtn.selected = YES; [_playPauseBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.mas_equalTo(-54); make.height.mas_equalTo(32); make.width.mas_equalTo(32); make.centerX.mas_equalTo(0); }]; //下一首按钮 _playNextBtn = [mgr df_nextBtnWithFrame:CGRectZero image:nextImage superView:self.view block:nil]; [_playNextBtn setImage:[UIImage imageNamed:@"dfplayer_next_none"] forState:UIControlStateDisabled]; [_playNextBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(_playPauseBtn.mas_centerY).offset(0); make.height.mas_equalTo(32); make.width.mas_equalTo(32); make.left.equalTo(_playPauseBtn.mas_right).offset(50); }]; //上一首按钮 _playLastBtn = [mgr df_lastBtnWithFrame:CGRectZero image:lastImage superView:self.view block:nil]; [_playLastBtn setImage:[UIImage imageNamed:@"dfplayer_last_none"] forState:UIControlStateDisabled]; [_playLastBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(_playPauseBtn.mas_centerY).offset(0); make.height.mas_equalTo(32); make.width.mas_equalTo(32); make.right.equalTo(_playPauseBtn.mas_left).offset(-50); }]; //歌单 _playListBtn = [[UIButton alloc] init]; [_playListBtn setImage:[UIImage imageNamed:@"dfplayer_playlist"] forState:UIControlStateNormal]; [_playListBtn addTarget:self action:@selector(didClickPlayListFun) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:_playListBtn]; [_playListBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(_playPauseBtn.mas_centerY).offset(0); make.height.mas_equalTo(25); make.width.mas_equalTo(25); //make.left.equalTo(_playNextBtn.mas_right).offset(50); make.right.mas_equalTo(-20); }]; // //播放模式按钮 // [mgr df_typeBtnWithFrame:typeRect singleImage:singleImage circleImage:circleImage shuffleImage:shuffleImage superView:_bgView block:nil]; //播放模型 _playModelBtn = [[UIButton alloc] init]; [_playModelBtn setImage:[UIImage imageNamed:@"dfplayer_circle"] forState:UIControlStateNormal]; [_playModelBtn addTarget:self action:@selector(didClickPlayModelButtonFun:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:_playModelBtn]; [_playModelBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(_playPauseBtn.mas_centerY).offset(0); make.height.mas_equalTo(25); make.width.mas_equalTo(25); make.left.mas_equalTo(20); }]; //进度条 UISlider * curSlider = [mgr df_sliderWithFrame:CGRectZero minimumTrackTintColor:[UIColor hwColor:@"#0CDEFD"] maximumTrackTintColor:[UIColor hwColor:@"#E3E3E3"] trackHeight:4 thumbImage:[ovalImage imageByResizeToSize:(CGSize){15,14}] superView:self.view]; [curSlider mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(_playPauseBtn.mas_top).offset(-40); make.height.mas_equalTo(40); make.left.mas_equalTo(70); make.right.mas_equalTo(-70); }]; //当前时间 UILabel *currentTimeLabel =[mgr df_currentTimeLabelWithFrame:CGRectZero textColor:[UIColor hwColor:@"#999999"] textAlignment:(NSTextAlignmentCenter) font:[UIFont systemFontOfSize:14.0] superView:self.view]; [currentTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(curSlider.mas_top).offset(0); make.height.mas_equalTo(40); make.left.mas_equalTo(5); make.right.equalTo(curSlider.mas_left).offset(-5); }]; //总时间 UILabel *totalTimeLabel = [mgr df_totalTimeLabelWithFrame:CGRectZero textColor:[UIColor hwColor:@"#999999"] textAlignment:(NSTextAlignmentCenter) font:[UIFont systemFontOfSize:14.0] superView:self.view]; [totalTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(curSlider.mas_top).offset(0); make.height.mas_equalTo(40); make.right.mas_equalTo(-5); make.left.equalTo(curSlider.mas_right).offset(5); }]; } #pragma mark 开始和暂停 按钮点击时间 - (void)playOrPauseButtonDidClickFun:(UIButton*)but { but.selected = !but.selected; if(but.selected){ [self startRotatingImage]; [self startPlayingRotateRightImage]; [[DFPlayer sharedPlayer] df_play]; } else{ [self stopRotatingImage]; [self stopPlayingRotateRightImage]; [[DFPlayer sharedPlayer] df_pause]; } } #pragma mark 开始和暂停 按钮点击时间 - (void)didClickPlayModelButtonFun:(UIButton*)but { switch ([DFPlayer sharedPlayer].playMode) { case DFPlayerModeSingleCycle://单曲循环->顺序循环 [DFPlayer sharedPlayer].playMode = DFPlayerModeOrderCycle; [but setImage:[UIImage imageNamed:@"dfplayer_circle"] forState:UIControlStateNormal]; [[iToast makeText:NSLocalizedString(@"NAS_audio_playModel_circle",nil)] show]; break; case DFPlayerModeOrderCycle://顺序循环->随机循环 [DFPlayer sharedPlayer].playMode = DFPlayerModeShuffleCycle; [but setImage:[UIImage imageNamed:@"dfplayer_shuffle"] forState:UIControlStateNormal]; [[iToast makeText:NSLocalizedString(@"NAS_audio_playModel_shuffle",nil)] show]; break; case DFPlayerModeShuffleCycle://随机循环->单曲循环 [DFPlayer sharedPlayer].playMode = DFPlayerModeSingleCycle; [but setImage:[UIImage imageNamed:@"dfplayer_single"] forState:UIControlStateNormal]; [[iToast makeText:NSLocalizedString(@"NAS_audio_playModel_single",nil)] show]; break; default: break; } } #pragma mark 点击右上角 更多或分享 - (void)didClickHeadButtonFun:(UIButton*)but { NSInteger tag = but.tag; if(tag == 1){ previewAudioPortraitTopMoreView *topMoreV = [[previewAudioPortraitTopMoreView alloc] init]; [self.view addSubview:topMoreV]; [topMoreV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); make.right.mas_equalTo(0); make.left.mas_equalTo(0); }]; KWeakSelf topMoreV.didClickButtonFun = ^(NSInteger tag) { switch (tag) { case 10: [weakSelf gotoDownLoadFileFun]; break; case 11: [weakSelf showDeleteAlearViewFun]; break; case 12: [weakSelf didClickDetailsFun]; break; default: break; } }; } else if (tag == 2){ [self gotoShareViewFun]; } } #pragma mark 用户点击分享 - (void)gotoShareViewFun { editShareView *editShareV = [[editShareView alloc] init]; NASFileAudioDataModel *dataModel = _allAudioDataArray[_index]; editShareV.didSelectListArr = [NSMutableArray arrayWithArray:@[dataModel]]; editShareV.shareFileType = @"4"; [self.view addSubview:editShareV]; [editShareV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(0); make.top.mas_equalTo(0); }]; } #pragma mark 用户点击下载 - (void)gotoDownLoadFileFun { NASFileAudioDataModel *dataModel = _allAudioDataArray[_index]; couldPhoneFileModel* fileModel = [couldPhoneFileModel new]; fileModel.fileType = @"audio"; fileModel.path = dataModel.path; fileModel.name = dataModel.name; fileModel.length = dataModel.size; NSMutableArray *arr = [NSMutableArray new]; [arr addObject:fileModel]; uploadFileRecordViewController *vc = [uploadFileRecordViewController new]; [self.navigationController pushViewController:vc animated:YES]; vc.isDownloadingType = YES; [vc gotoDownloadFile:arr]; } #pragma mark 用户点击删除 - (void)showDeleteAlearViewFun { NSString *titleStr = NSLocalizedString(@"delete_file_title_msg",nil); NSString *tipStr = NSLocalizedString(@"delete_file_tip_msg",nil); KWeakSelf ComontAlretViewController *curAlretVC= [[ComontAlretViewController alloc] initWithTiTle:titleStr msg:tipStr imageStr:nil cancelTitle:NSLocalizedString(@"other_cancel",nil) okTitle:NSLocalizedString(@"other_confirm",nil) isOkBtnHighlight:YES didClickOk:^{ [weakSelf delFileListFun]; } didClickCancel:^{ }]; curAlretVC.modalPresentationStyle = UIModalPresentationCustom; [self presentViewController:curAlretVC animated:YES completion:^{ curAlretVC.view.superview.backgroundColor = [UIColor clearColor]; }]; } #pragma mark 删除文件数据 - (void)delFileListFun { NSMutableDictionary*paraDict = [NSMutableDictionary new]; NSMutableArray *pathArr = [NSMutableArray new]; NASFileAudioDataModel *dataModel = _allAudioDataArray[_index]; [pathArr addObject:dataModel.path]; [paraDict setValue:pathArr forKey:@"path"]; [self showNewIndicatorWithCanBack:YES canTouch:NO]; //NSString*code = [[NSString alloc] initWithFormat:@"delFile?path=%@",paraDict[@"path"]]; //delFile?path=[/storage/emulated/0/Download/IMG_6464.HEIC] KWeakSelf //@"delFile" [[netWorkManager shareInstance] cloudPhonePostCallBackCode:@"delFile" Parameters:paraDict success:^(id _Nonnull responseObject) { [weakSelf removeNewIndicator]; SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil]; if(model && model.status == 0){ [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show]; [weakSelf didDeleteSucFun:dataModel.path]; } else{ } } failure:^(NSError * _Nonnull error) { [weakSelf removeNewIndicator]; }]; } #pragma mark 删除成功 - (void)didDeleteSucFun:(NSString*)path { //1.删除最近文件数据 [[lastFileManager shareManager] deleteFileInfoWithUrl:path]; [[audioPlayListManager shareManager] deleteFileInfoWithUrl:path]; if(_didNeedToRegetDataFun){ _didNeedToRegetDataFun(); } [self.navigationController popViewControllerAnimated:YES]; } #pragma mark 用户点击详情 - (void)didClickDetailsFun { NSMutableArray *pathArr = [NSMutableArray new]; NASFileAudioDataModel *dataModel = _allAudioDataArray[_index]; previewAudioPortraitDetailsView *topDetailsV = [[previewAudioPortraitDetailsView alloc] initWithFrame:CGRectZero withData:dataModel]; [self.view addSubview:topDetailsV]; [topDetailsV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); make.right.mas_equalTo(0); make.left.mas_equalTo(0); }]; } #pragma mark 用户点击播放列表 - (void)didClickPlayListFun { _audioPlayListV = [[audioPlayListView alloc] initWithFrame:CGRectZero withIndex:_index]; [self.view addSubview:_audioPlayListV]; [_audioPlayListV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); make.right.mas_equalTo(0); make.left.mas_equalTo(0); }]; KWeakSelf _audioPlayListV.didClickButtonFun = ^{ [weakSelf gotoAddAudioToPlayListVCFun]; }; } #pragma mark 跳转添加音乐到播放列表 - (void)gotoAddAudioToPlayListVCFun { addAudioToPlayListViewController *vc = [addAudioToPlayListViewController new]; [self.navigationController pushViewController:vc animated:YES]; KWeakSelf vc.didNeedToRegetAudioPlayListFun = ^{ [weakSelf.audioPlayListV reGetDataFun]; [weakSelf AddNewAudioToListFun]; }; } #pragma mark 处理本地是否需要添加新加的的音乐 - (void)AddNewAudioToListFun { [[DFPlayer sharedPlayer] df_reloadData]; } #pragma mark - DFPLayer dataSource - (NSArray *)df_audioDataForPlayer:(DFPlayer *)player{ _dataArray = [NSMutableArray array]; _allAudioDataArray = [NSMutableArray array]; //首次进来 if(_isfirstEnterType){ _isfirstEnterType = NO; //把外面传入的音频作为第一次传入 NASFileAudioDataModel *yourModel = _outSideDataModel; DFPlayerModel *model = [[DFPlayerModel alloc] init]; model.audioId = 0;//****重要。AudioId从0开始,仅标识当前音频在数组中的位置。 NSString *filePath = yourModel.path; NSString *urlStr = ksharedAppDelegate.NASFileByBoxService; NSString *string = filePath; NSString *filePathBase64 = [iTools base64UrlEncoder:string]; NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getFiles/%@",urlStr,filePathBase64]; NSURL * curURL = [NSURL fileURLWithPath:fileUrl]; model.audioUrl = curURL; HLog(@"%@",curURL.absoluteString); [_dataArray addObject:model]; [_allAudioDataArray addObject:yourModel]; } //把播放列表的数据同步进来 NSMutableArray *localList = [audioPlayListManager shareManager].audioPlayListArr; if(localList.count > 0){ NSInteger curIndex = _dataArray.count; for (NSInteger i = 0; i < localList.count; i++) { NASFileAudioDataModel *yourModel = localList[i]; DFPlayerModel *model = [[DFPlayerModel alloc] init]; model.audioId = i + curIndex;//****重要。AudioId从0开始,仅标识当前音频在数组中的位置。 NSString *filePath = yourModel.path; NSString *urlStr = ksharedAppDelegate.NASFileByBoxService; NSString *string = filePath; NSString *filePathBase64 = [iTools base64UrlEncoder:string]; NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getFiles/%@",urlStr,filePathBase64]; NSURL * curURL = [NSURL fileURLWithPath:fileUrl]; model.audioUrl = curURL; HLog(@"%@",curURL.absoluteString); [_dataArray addObject:model]; [_allAudioDataArray addObject:yourModel]; } } HLog(@"%@ --- %ld",_dataArray,_dataArray.count); return [_dataArray copy]; // if ([yourModel.yourUrl hasPrefix:@"http"]) {//网络音频 // model.audioUrl = [self getAvailableURL:yourModel.yourUrl]; // }else{//本地音频 // NSString *path = [[NSBundle mainBundle] pathForResource:yourModel.yourUrl ofType:@""]; // if (path) { // model.audioUrl = [NSURL fileURLWithPath:path]; // } // } } - (DFPlayerInfoModel *)df_audioInfoForPlayer:(DFPlayer *)player{ DFPlayerInfoModel *infoModel = [[DFPlayerInfoModel alloc] init]; // infoModel.audioName = @"";//yourModel.yourName; // infoModel.audioSinger = @"";//yourModel.yourSinger; // infoModel.audioAlbum = @"";//yourModel.yourAlbum; // infoModel.audioLyrics = @"";//[NSString stringWithContentsOfFile:lyricPath encoding:NSUTF8StringEncoding error:nil]; //infoModel.audioImage = [UIImage imageWithData:imageData]; return infoModel; } #pragma mark - DFPlayer delegate //加入播放队列 - (void)df_playerAudioAddToPlayQueue:(DFPlayer *)player{ // [self tableViewReloadData]; // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // dispatch_async(dispatch_get_main_queue(), ^{ // self.navigationItem.title = player.currentAudioInfoModel.audioName; // self->_bgView.image = [self getBackgroundImage:player.currentAudioInfoModel.audioImage]; // self->_noticeLabel.text = player.currentAudioInfoModel.audioLyrics ? @"" : @"无可用歌词"; // }); // }); } //缓冲进度代理 - (void)df_player:(DFPlayer *)player bufferProgress:(CGFloat)bufferProgress{ HLog(@"缓冲进度代理:%f",bufferProgress); } //播放进度代理 - (void)df_player:(DFPlayer *)player progress:(CGFloat)progress currentTime:(CGFloat)currentTime{ HLog(@"音频播放进度:%f --- %f",progress,currentTime); if(_lastAudioIndex != player.currentAudioModel.audioId){ _lastAudioIndex = player.currentAudioModel.audioId; _index = _lastAudioIndex; [self setTitleFunByIndex]; [self audioPlayerByIndex:_lastAudioIndex]; [self startRotatingImage]; [self startPlayingRotateRightImage]; } if(progress >= 1.0){ _lastAudioIndex = -1; [self stopRotatingImage]; } } //状态信息代理 - (void)df_player:(DFPlayer *)player didGetStatusCode:(DFPlayerStatusCode)statusCode{ if (statusCode == DFPlayerStatusNoNetwork) { //[self showAlert:@"没有网络连接"]; }else if(statusCode == DFPlayerStatusViaWWAN){ // [self showAlert:@"继续播放将产生流量费用" okBlock:^{ // [DFPlayer sharedPlayer].isObserveWWAN = NO; // [[DFPlayer sharedPlayer] df_playWithAudioId:player.currentAudioModel.audioId]; // }]; [DFPlayer sharedPlayer].isObserveWWAN = NO; [[DFPlayer sharedPlayer] df_playWithAudioId:player.currentAudioModel.audioId]; }else if(statusCode == DFPlayerStatusTimeOut){ //[self showAlert:@"请求超时"]; }else if(statusCode == DFPlayerStatusCacheSucc){ [[DFPlayer sharedPlayer] df_playWithAudioId:player.currentAudioModel.audioId]; }else{ HLog(@"状态码:%lu",(unsigned long)statusCode); [[iToast makeText:NSLocalizedString(@"play_video_fail_tip",nil)] show]; [[DFPlayer sharedPlayer] df_next]; } } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self setTitleFunByIndex]; [[DFPlayer sharedPlayer] df_reloadData];//需在传入数据源后调用 KWeakSelf dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakSelf playAudioFun]; }); } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; //[[DFPlayer sharedPlayer] df_deallocPlayer]; } -(void)setTitleFunByIndex { if(_index < _allAudioDataArray.count){ NASFileAudioDataModel* dataModel = _allAudioDataArray[_index]; //self.titleLabel.text = dataModel.name; _AudioTitleLab.text = dataModel.name; if(_audioPlayListV){ _audioPlayListV.playingIndex = _index; } } } - (void)playAudioFun { if(_index < self.dataArray.count){ DFPlayerModel *model = self.dataArray[_index]; [[DFPlayer sharedPlayer] df_playWithAudioId:model.audioId]; } } #pragma mark 音频可以播放 - (void)audioPlayerByIndex:(NSInteger)index{ if(index >=0 && index < _allAudioDataArray.count){ NASFileAudioDataModel *dataModel = _allAudioDataArray[index]; lastFileModel *lastFileMod = [lastFileModel new]; lastFileMod.path = dataModel.path; lastFileMod.name = dataModel.name; lastFileMod.time = dataModel.time; lastFileMod.size = dataModel.size; lastFileMod.duration = dataModel.duration; lastFileMod.type = @"audio"; lastFileMod.lastPreTime = [iTools getNowTimeStamp]; [[lastFileManager shareManager] saveFileInfoWith:lastFileMod with:dataModel.path]; [[audioPlayListManager shareManager] saveFileInfoWith:lastFileMod with:dataModel.path]; } } #pragma mark 图片旋转相关 - (void)startRotatingImage { // 停止当前动画(如果有的话) [self stopRotatingImage]; // 创建一个CABasicAnimation实例 self.rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; // 设置动画的起始值(从0度开始) self.rotationAnimation.fromValue = [NSNumber numberWithFloat:0]; // 设置动画的结束值(旋转360度,注意这里是弧度制) self.rotationAnimation.toValue = [NSNumber numberWithFloat:M_PI * 2]; // 设置动画的持续时间 self.rotationAnimation.duration = 5.0; // 可以根据需要调整旋转速度 // 设置动画的重复次数,这里设置为HUGE_VALF表示无限次 self.rotationAnimation.repeatCount = HUGE_VALF; // 将动画添加到imageView的layer上 [self.bgImageView.layer addAnimation:self.rotationAnimation forKey:@"rotateAnimation"]; } - (void)stopRotatingImage { // 移除imageView上的动画 [self.bgImageView.layer removeAnimationForKey:@"rotateAnimation"]; [UIView animateWithDuration:5 animations:^{ self.bgImageView.layer.transform = CATransform3DIdentity; }]; } - (void)restartRotatingImage { // 直接调用startRotatingImage来重新启动动画 [self startRotatingImage]; } - (void)startPlayingRotateRightImage { [UIView animateWithDuration:2 animations:^{ self.playImageView.transform = CGAffineTransformMakeRotation(0); //self.playImageView.transform = CGAffineTransformRotate(self.playImageView.transform, -M_PI / 6); // 逆时针旋转30度 }]; } - (void)stopPlayingRotateRightImage { [UIView animateWithDuration:2 animations:^{ self.playImageView.transform = CGAffineTransformMakeRotation(-M_PI*0.15); }]; } //改变旋转中心??? - (void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view { CGPoint oldOrigin = view.frame.origin; view.layer.anchorPoint = anchorPoint; CGPoint newOrigin = view.frame.origin; CGPoint transition; transition.x = newOrigin.x - oldOrigin.x; transition.y = newOrigin.y - oldOrigin.y; view.center = CGPointMake (view.center.x - transition.x, view.center.y - transition.y); } @end