123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044 |
- //
- // 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 <QuartzCore/QuartzCore.h>
- #import "previewAudioPortraitTopMoreView.h"
- #import "editShareView.h"
- #import "uploadFileRecordViewController.h"
- #import "previewAudioPortraitDetailsView.h"
- #import "audioPlayListView.h"
- #import "addAudioToPlayListViewController.h"
- @interface audioPlayerViewController ()<DFPlayerDelegate,DFPlayerDataSource>
- {
- NSInteger playDelayed;
- }
- @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;//所有的 播放数据(lastFileModel)
- @property (nonatomic, strong) NSMutableArray<DFPlayerModel *> *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;
-
- //数据埋点
- [[netWorkManager shareInstance] DataEmbeddingPointBy:4 withEventValue:@"Music_preview"];
- }
- - (void)viewDidAppear:(BOOL)animated
- {
- [super viewDidAppear:animated];
-
- if(_outSideDataModel && _isfirstEnterType){
-
- [[DFPlayer sharedPlayer] df_pause];
- [[DFPlayer sharedPlayer] df_reloadData];//需在传入数据源后调用
-
- [self setTitleFunByIndex];
-
- //begin 20240729 修复音频播放时,进入播放列表点击当前播放歌曲后,会重头播放
- if([DFPlayer sharedPlayer].currentAudioModel){
- NSString *filePath = _outSideDataModel.path;
-
- if([[DFPlayer sharedPlayer].currentAudioModel.filePath isEqualToString:filePath]){
- [[DFPlayer sharedPlayer] df_play];
- return;//不重新播放
- }
- }//end 20240729 修复音频播放时,进入播放列表点击当前播放歌曲后,会重头播放
-
- KWeakSelf
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [weakSelf playAudioFun];
- });
-
- }
- else{//点击playingview 进来的
-
- _allAudioDataArray = [audioPlayListManager shareManager].audioPlayListArr;
- _lastAudioIndex = -1;
- _index = [DFPlayer sharedPlayer].currentAudioModel.audioId;
- [self setTitleFunByIndex];
- [self handleSomeUIFun];
- }
- }
- - (void)viewDidDisappear:(BOOL)animated
- {
- [super viewDidDisappear:animated];
- //[[DFPlayer sharedPlayer] df_deallocPlayer];
- }
- - (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{
-
- NSInteger playMode = [HWDataManager getIntegerWithKey:@"Const_audio_playMode_record"];
-
- [[DFPlayer sharedPlayer] df_initPlayerWithUserId:nil];
- [DFPlayer sharedPlayer].dataSource = self;
- [DFPlayer sharedPlayer].delegate = self;
- if(playMode <= DFPlayerModeOnlyOnce || playMode > DFPlayerModeShuffleCycle){
- [DFPlayer sharedPlayer].playMode = DFPlayerModeOrderCycle;
- }
- else{
- [DFPlayer sharedPlayer].playMode = playMode;
- }
-
- [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];
-
- if([DFPlayer sharedPlayer].state == DFPlayerStatePause){
- _playPauseBtn.selected = NO;
- }
- else{
- _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 = [[UIButton alloc] init];
- [_playNextBtn setImage:[UIImage imageNamed:@"dfplayer_next_none"] forState:UIControlStateDisabled];
- [_playNextBtn setImage:nextImage forState:UIControlStateNormal];
- [_playNextBtn addTarget:self action:@selector(playNextButtonFun) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:_playNextBtn];
- [_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 = [[UIButton alloc] init];
- [_playLastBtn setImage:[UIImage imageNamed:@"dfplayer_last_none"] forState:UIControlStateDisabled];
- [_playLastBtn setImage:lastImage forState:UIControlStateNormal];
- [_playLastBtn addTarget:self action:@selector(playLastButtonFun) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:_playLastBtn];
-
- [_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];
- UIImage *playModelImage = [UIImage imageNamed:@"dfplayer_circle"];
-
- if ([DFPlayer sharedPlayer].playMode == DFPlayerModeShuffleCycle){
- playModelImage = [UIImage imageNamed:@"dfplayer_shuffle"];
- }
- else if ([DFPlayer sharedPlayer].playMode == DFPlayerModeSingleCycle){
- playModelImage = [UIImage imageNamed:@"dfplayer_single"];
- }
-
- //播放模型
- _playModelBtn = [[UIButton alloc] init];
- [_playModelBtn setImage:playModelImage 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];
-
- playDelayed = 0;
- [[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;
- }
-
- [HWDataManager setIntegerWithKey:@"Const_audio_playMode_record" value:[DFPlayer sharedPlayer].playMode];
- }
- #pragma mark 点击下一首
- - (void)playNextButtonFun
- {
- [[DFPlayer sharedPlayer] df_next];
- }
- #pragma mark 点击上一首
- - (void)playLastButtonFun
- {
- [[DFPlayer sharedPlayer] df_last];
- }
- #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 = dataModel.type;
- 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:@""
- 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];
- }];
-
- //数据埋点
- [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Music_delete"];
-
- }
- #pragma mark 删除成功
- - (void)didDeleteSucFun:(NSString*)path
- {
- //1.删除最近文件数据
- [[lastFileManager shareManager] deleteFileInfoWithUrl:path];
- [[audioPlayListManager shareManager] deleteFileInfoWithUrl:path];
-
-
- if(_didNeedToRegetDataFun){
- _didNeedToRegetDataFun();
- }
-
- if([audioPlayListManager shareManager].audioPlayListArr.count >= 1){
- _isfirstEnterType = NO;
- [[DFPlayer sharedPlayer] df_reloadData];
-
- if([DFPlayer sharedPlayer].playerModelArray.count > _index){
- [[DFPlayer sharedPlayer] df_playWithAudioId:_index];
- }
- else{
- [[DFPlayer sharedPlayer] df_playWithAudioId:0];
- }
- }
- else{
- [self.navigationController popViewControllerAnimated:YES];
- }
-
-
-
-
- }
- #pragma mark 用户点击详情
- - (void)didClickDetailsFun
- {
- 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];
- };
-
- _audioPlayListV.didClickDeleteFun = ^(lastFileModel * _Nonnull dataModel) {
- [weakSelf deleteAudioToListBy:dataModel];
- };
-
- _audioPlayListV.didClickAudioFun = ^(NSInteger row) {
- [[DFPlayer sharedPlayer] df_playWithAudioId:row];
- };
- }
- #pragma mark 处理本地是否需要添加新加的的音乐
- - (void)deleteAudioToListBy:(lastFileModel*)dataModel
- {
- [[lastFileManager shareManager] deleteFileInfoWithUrl:dataModel.path];
- [[audioPlayListManager shareManager] deleteFileInfoWithUrl:dataModel.path];
-
- [[DFPlayer sharedPlayer] df_reloadData];
-
- KWeakSelf
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [weakSelf.audioPlayListV reGetDataFun];
- });
- }
- #pragma mark 跳转添加音乐到播放列表
- - (void)gotoAddAudioToPlayListVCFun
- {
- addAudioToPlayListViewController *vc = [addAudioToPlayListViewController new];
- [self.navigationController pushViewController:vc animated:YES];
-
- KWeakSelf
- vc.didNeedToRegetAudioPlayListFun = ^{
- [weakSelf AddNewAudioToListFun];
- };
- }
- #pragma mark 处理本地是否需要添加新加的的音乐
- - (void)AddNewAudioToListFun
- {
- [[DFPlayer sharedPlayer] df_reloadData];
-
- KWeakSelf
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [weakSelf.audioPlayListV reGetDataFun];
- });
- }
- #pragma mark 处理一些UI问题
- - (void)handleSomeUIFun
- {
- if(_allAudioDataArray.count <= 1){
- _playLastBtn.enabled = NO;
- _playNextBtn.enabled = NO;
- }
- else{
- _playLastBtn.enabled = YES;
- _playNextBtn.enabled = YES;
- }
- }
- #pragma mark - DFPLayer dataSource
- - (NSArray<DFPlayerModel *> *)df_audioDataForPlayer:(DFPlayer *)player{
- _dataArray = [NSMutableArray array];
- _allAudioDataArray = [NSMutableArray array];
- //把播放列表的数据同步进来
- NSMutableArray *localList = [audioPlayListManager shareManager].audioPlayListArr;
-
- if(localList.count > 0){
- for (NSInteger i = 0; i < localList.count; i++)
- {
- lastFileModel *yourModel = localList[i];
- DFPlayerModel *model = [[DFPlayerModel alloc] init];
- model.audioId = i;//****重要。AudioId从0开始,仅标识当前音频在数组中的位置。
- model.filePath = yourModel.path;
-
- NSString *filePath = yourModel.path;
- NSString *urlStr = ksharedAppDelegate.NASFileByBoxService;
-
- NSString *filePathBase64 = [iTools base64UrlEncoder:filePath];
-
- 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];
-
- //20240729 修复添加音乐时显示名称不对
- if([DFPlayer sharedPlayer].currentAudioModel){
- if([[DFPlayer sharedPlayer].currentAudioModel.filePath isEqualToString:filePath]){
- _index = i;
- }
- }
- }
- }
-
- //首次进来 //需要判断原来的播放列表中是否存在音频
- if(_isfirstEnterType){
-
- //把外面传入的音频作为第一次传入
- lastFileModel *lastFileMod = [lastFileModel new];
- lastFileMod.path = _outSideDataModel.path;
- lastFileMod.name = _outSideDataModel.name;
- lastFileMod.time = _outSideDataModel.time;
- lastFileMod.size = _outSideDataModel.size;
- lastFileMod.duration = _outSideDataModel.duration;
- lastFileMod.type = @"audio";
- lastFileMod.lastPreTime = [iTools getNowTimeStamp];
- //本地缓存
- lastFileMod.localPath = [[audioPlayListManager shareManager] getAudioCacheFullPathBy:_outSideDataModel.name];
-
- DFPlayerModel *model = [[DFPlayerModel alloc] init];
- model.audioId = 0;//****重要。AudioId从0开始,仅标识当前音频在数组中的位置。
- NSString *filePath = lastFileMod.path;
- model.filePath = filePath;
-
- BOOL isInLocalListType = NO;
-
- for (NSInteger i = 0; i < localList.count; i++){
- NASFileAudioDataModel * model = _allAudioDataArray[i];
- if([model.path isEqualToString:filePath]){
- isInLocalListType = YES;
- _index = i;
- break;
- }
- }
-
- if(!isInLocalListType){
- NSString *urlStr = ksharedAppDelegate.NASFileByBoxService;
-
- NSString *filePathBase64 = [iTools base64UrlEncoder:filePath];
-
- NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getFiles/%@",urlStr,filePathBase64];
-
- NSURL * curURL = [NSURL fileURLWithPath:fileUrl];
- model.audioUrl = curURL;
- HLog(@"%@",curURL.absoluteString);
- [_dataArray insertObject:model atIndex:0];
- [_allAudioDataArray insertObject:lastFileMod atIndex:0];
-
- [[audioPlayListManager shareManager] saveFileInfoWith:lastFileMod with:lastFileMod.path];
- _index = 0;
-
- //有数据插入 重新排序audioId
- for (NSInteger i = 0; i < _dataArray.count; i++) {
- DFPlayerModel *model = _dataArray[i];
- model.audioId = i;
- }
- }
-
- _isfirstEnterType = NO;
- }
-
- HLog(@"hxd :%@ --- %ld---index:%ld",_dataArray,_dataArray.count,_index);
-
- mainBlock(^{
- [self handleSomeUIFun];
- });
-
- return [_dataArray copy];
-
- //本地音频
- // 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{
-
- }
- //缓冲进度代理
- - (void)df_player:(DFPlayer *)player bufferProgress:(CGFloat)bufferProgress{
- NSInteger index = player.currentAudioModel.audioId;
- if(index >0 && index<_dataArray.count){
- lastFileModel *lastFileMod = _allAudioDataArray[index];
- HLog(@"缓冲进度代理:%f --- %@",bufferProgress,lastFileMod.name);
- }
- else{
- HLog(@"缓冲进度代理:%f",bufferProgress);
- }
-
-
- }
- //播放进度代理
- - (void)df_player:(DFPlayer *)player progress:(CGFloat)progress currentTime:(CGFloat)currentTime{
-
- NSInteger index = player.currentAudioModel.audioId;
- if(index >0 && index<_dataArray.count){
- lastFileModel *lastFileMod = _allAudioDataArray[index];
- //HLog(@"音频播放进度:%f --- %f --- %@ ---inddex:%ld ---- %ld",progress,currentTime,lastFileMod.name,_lastAudioIndex,index);
- }
- else{
- //HLog(@"音频播放进度:%f --- %f",progress,currentTime);
- }
-
-
- playDelayed ++;
- if(!_playPauseBtn.selected && playDelayed >= 3){
- _playPauseBtn.selected = YES;
- }
-
- //HLog(@"df_player progress hxd _ind:%ld ---- %ld",_lastAudioIndex,player.currentAudioModel.audioId);
- if(_lastAudioIndex != player.currentAudioModel.audioId)
- {
- _lastAudioIndex = player.currentAudioModel.audioId;
- _index = _lastAudioIndex;
- // HLog(@"df_player progress hxd _ind:setTitleFunByIndex");
- // [self setTitleFunByIndex];
- [self audioPlayerByIndex:_lastAudioIndex];
-
- [self startRotatingImage];
- [self startPlayingRotateRightImage];
- }
-
- //尝试强行修改 歌曲名 后续有时间优化
- _lastAudioIndex = player.currentAudioModel.audioId;
- _index = _lastAudioIndex;
- //HLog(@"df_player progress hxd _ind:setTitleFunByIndex");
- [self setTitleFunByIndex];
-
- 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];
-
- _lastAudioIndex = -1;
- if(_dataArray.count == 1){//只有一首的情况
- [self stopRotatingImage];
- [self stopPlayingRotateRightImage];
- _playPauseBtn.selected = NO;
- }
- else{
- [[DFPlayer sharedPlayer] df_next];
- }
- }
- }
- -(void)setTitleFunByIndex
- {
- //HLog(@"setTitleFunByIndex")
- if(!_allAudioDataArray){
- KWeakSelf
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [weakSelf setTitleFunByIndex];
- });
- return;
- }
-
- if(_index < _allAudioDataArray.count){
- lastFileModel* dataModel = _allAudioDataArray[_index];
- //self.titleLabel.text = dataModel.name;
- _AudioTitleLab.text = dataModel.name;
-
- if(_audioPlayListV){
- _audioPlayListV.playingIndex = _index;
- }
- //HLog(@"hxd _index:%ld name:%@",_index,dataModel.name)
- }
- }
- - (void)playAudioFun
- {
- HLog(@"playAudioFun-index:%ld",_index)
- 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];
-
- //本地缓存
- lastFileMod.localPath = [[audioPlayListManager shareManager] getAudioCacheFullPathBy:dataModel.name];
-
- [[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
|