Ver código fonte

1.音频播放--改造中

huangxiaodong 11 meses atrás
pai
commit
bcbbd0690f

+ 105 - 37
创维盒子/双子星云手机/Class/Set/previewFile/audioPlayerViewController.m

@@ -199,8 +199,13 @@
     
     
     //下一首按钮
-    _playNextBtn = [mgr df_nextBtnWithFrame:CGRectZero image:nextImage superView:self.view block:nil];
+    //_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);
@@ -209,8 +214,12 @@
     }];
     
     //上一首按钮
-    _playLastBtn = [mgr df_lastBtnWithFrame:CGRectZero image:lastImage superView:self.view block:nil];
+    //_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);
@@ -314,7 +323,7 @@
     }
 }
 
-#pragma mark 开始和暂停 按钮点击时间
+#pragma mark  按钮点击 播放模型
 - (void)didClickPlayModelButtonFun:(UIButton*)but
 {
     switch ([DFPlayer sharedPlayer].playMode) {
@@ -339,6 +348,18 @@
     
 }
 
+#pragma mark 点击下一首
+- (void)playNextButtonFun
+{
+    [[DFPlayer sharedPlayer] df_next];
+}
+
+#pragma mark 点击上一首
+- (void)playLastButtonFun
+{
+    [[DFPlayer sharedPlayer] df_last];
+}
+
 #pragma mark 点击右上角 更多或分享
 - (void)didClickHeadButtonFun:(UIButton*)but
 {
@@ -425,7 +446,7 @@
     KWeakSelf
     ComontAlretViewController *curAlretVC= [[ComontAlretViewController alloc] initWithTiTle:titleStr
                                                                                       msg:tipStr
-                                                                                 imageStr:nil
+                                                                                 imageStr:@""
                                                                               cancelTitle:NSLocalizedString(@"other_cancel",nil)
                                                                                   okTitle:NSLocalizedString(@"other_confirm",nil) isOkBtnHighlight:YES
                                                                                didClickOk:^{
@@ -489,7 +510,6 @@
 #pragma mark 用户点击详情
 - (void)didClickDetailsFun
 {
-    NSMutableArray *pathArr = [NSMutableArray new];
     NASFileAudioDataModel *dataModel = _allAudioDataArray[_index];
     
     previewAudioPortraitDetailsView *topDetailsV = [[previewAudioPortraitDetailsView alloc] initWithFrame:CGRectZero withData:dataModel];
@@ -520,6 +540,21 @@
     _audioPlayListV.didClickButtonFun = ^{
         [weakSelf gotoAddAudioToPlayListVCFun];
     };
+    
+    _audioPlayListV.didClickDeleteFun = ^(lastFileModel * _Nonnull dataModel) {
+        [weakSelf deleteAudioToListBy:dataModel];
+    };
+}
+
+#pragma mark 处理本地是否需要添加新加的的音乐
+- (void)deleteAudioToListBy:(lastFileModel*)dataModel
+{
+    [[lastFileManager shareManager] deleteFileInfoWithUrl:dataModel.path];
+    [[audioPlayListManager shareManager] deleteFileInfoWithUrl:dataModel.path];
+    
+    [[DFPlayer sharedPlayer] df_reloadData];
+    
+    [_audioPlayListV reGetDataFun];
 }
 
 #pragma mark 跳转添加音乐到播放列表
@@ -539,16 +574,53 @@
 - (void)AddNewAudioToListFun
 {
     [[DFPlayer sharedPlayer] df_reloadData];
-    
 }
 
+#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++)
+        {
+            NASFileAudioDataModel *yourModel = localList[i];
+            DFPlayerModel *model = [[DFPlayerModel alloc] init];
+            model.audioId = i;//****重要。AudioId从0开始,仅标识当前音频在数组中的位置。
+            
+            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];
+        }
+    }
+    
+    //首次进来 //需要判断原来的播放列表中是否存在音频
     if(_isfirstEnterType){
         _isfirstEnterType = NO;
         
@@ -556,52 +628,48 @@
         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];
+        BOOL isInLocalListType = NO;
         
-        NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getFiles/%@",urlStr,filePathBase64];
-       
-        NSURL * curURL =  [NSURL fileURLWithPath:fileUrl];
-        model.audioUrl = curURL;
-        HLog(@"%@",curURL.absoluteString);
-        [_dataArray addObject:model];
+        for (NSInteger i = 0; i < localList.count; i++){
+            NASFileAudioDataModel * model = _allAudioDataArray[i];
+            if([model.path isEqualToString:filePath]){
+                isInLocalListType = YES;
+                _index = i;
+                break;
+            }
+        }
         
-        [_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;
+        if(!isInLocalListType){
             NSString *urlStr = ksharedAppDelegate.NASFileByBoxService;
             
-            NSString *string = filePath;
-            NSString *filePathBase64 = [iTools base64UrlEncoder:string];
+            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];
+            [_dataArray insertObject:model atIndex:0];
+            [_allAudioDataArray insertObject:yourModel atIndex:0];
             
-            [_allAudioDataArray addObject:yourModel];
+            //有数据插入 重新排序audioId
+            for (NSInteger i = 0; i < _dataArray.count; i++) {
+                DFPlayerModel *model = _dataArray[i];
+                model.audioId = i;
+            }
         }
+        
     }
     
     HLog(@"%@ --- %ld",_dataArray,_dataArray.count);
+    
+    mainBlock(^{
+        [self handleSomeUIFun];
+    });
+    
     return [_dataArray copy];
     
     //        if ([yourModel.yourUrl hasPrefix:@"http"]) {//网络音频

+ 2 - 1
创维盒子/双子星云手机/Class/Set/previewFile/view/audioPlayListView.h

@@ -6,13 +6,14 @@
 //
 
 #import <UIKit/UIKit.h>
+#import "audioPlayListManager.h"
 
 NS_ASSUME_NONNULL_BEGIN
 
 @interface audioPlayListView : UIView
 @property (nonatomic,assign) NSInteger playingIndex;
 @property (nonatomic,copy) void (^didClickButtonFun)(void);
-
+@property (nonatomic,copy) void (^didClickDeleteFun)(lastFileModel* dataModel);
 - (id)initWithFrame:(CGRect)frame withIndex:(NSInteger)index;
 - (void)reGetDataFun;
 @end

+ 39 - 11
创维盒子/双子星云手机/Class/Set/previewFile/view/audioPlayListView.m

@@ -6,12 +6,12 @@
 //
 
 #import "audioPlayListView.h"
-#import "audioPlayListManager.h"
 #import "audioPlayListViewCell.h"
 
 @interface audioPlayListView ()<UITableViewDelegate,UITableViewDataSource>
 @property(nonatomic,strong) NSMutableArray*curDataArr;
 @property(nonatomic,strong) UILabel*leftTitleLab;
+@property(nonatomic,strong) UIView *whiteBgView;
 @property (nonatomic, strong) UITableView *tableView;
 @end
 
@@ -58,13 +58,13 @@
     }
     
     
-    UIView *whiteBgView = [[UIView alloc] init];
-    whiteBgView.backgroundColor = [UIColor whiteColor];
-    [self addSubview:whiteBgView];
-    whiteBgView.layer.cornerRadius = 12;
-    whiteBgView.layer.masksToBounds = YES;
+    _whiteBgView = [[UIView alloc] init];
+    _whiteBgView.backgroundColor = [UIColor whiteColor];
+    [self addSubview:_whiteBgView];
+    _whiteBgView.layer.cornerRadius = 12;
+    _whiteBgView.layer.masksToBounds = YES;
     
-    [whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) {
+    [_whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) {
         make.bottom.mas_equalTo(20);
         make.right.mas_equalTo(0);
         make.left.mas_equalTo(0);
@@ -77,7 +77,7 @@
     _leftTitleLab = [[UILabel alloc] init];
     _leftTitleLab.textColor = [UIColor hwColor:@"#0A132B"];
     _leftTitleLab.font = [UIFont systemFontOfSize:14.0];
-    [whiteBgView addSubview:_leftTitleLab];
+    [_whiteBgView addSubview:_leftTitleLab];
 
     [_leftTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
         make.left.mas_equalTo(15);
@@ -96,7 +96,7 @@
     addAudioBut.backgroundColor = [UIColor hwColor:@"#F3F3F3"];
     addAudioBut.layer.cornerRadius = 8;
     addAudioBut.layer.masksToBounds = YES;
-    [whiteBgView addSubview:addAudioBut];
+    [_whiteBgView addSubview:addAudioBut];
 
     [addAudioBut mas_makeConstraints:^(MASConstraintMaker *make) {
         make.right.mas_equalTo(-20);
@@ -106,7 +106,7 @@
     }];
     
     
-    [whiteBgView addSubview:self.tableView];
+    [_whiteBgView addSubview:self.tableView];
     [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
         make.left.mas_equalTo(0);
         make.right.mas_equalTo(0);
@@ -191,7 +191,7 @@
         
         KWeakSelf
         cell.didClickSwitch = ^(BOOL SwitchOn) {
-            
+            [weakSelf didClickAudioInPlayListBy:row];
         };
     }
     return cell;
@@ -216,6 +216,24 @@
     [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
     _leftTitleLab.attributedText = attrStr;
     
+    NSInteger count = _curDataArr.count;
+    if(count >5){
+        count = 5;
+    }
+    else if(count == 0){
+        count = 1;
+    }
+    
+    CGFloat topViewH = 52.0;
+    CGFloat bottomViewH = 20.0 + safeArea;
+    CGFloat tableViewCellH = 70.0;
+    [_whiteBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
+        make.bottom.mas_equalTo(20);
+        make.right.mas_equalTo(0);
+        make.left.mas_equalTo(0);
+        make.height.mas_equalTo(topViewH + bottomViewH +tableViewCellH*count);
+    }];
+    
     [self.tableView reloadData];
 }
 
@@ -245,5 +263,15 @@
 {
     [self setTitleStrFun];
 }
+
+#pragma mark 点击删除音频
+- (void)didClickAudioInPlayListBy:(NSInteger)row
+{
+    lastFileModel* dataModel = _curDataArr[row];
+    
+    if(_didClickDeleteFun){
+        _didClickDeleteFun(dataModel);
+    }
+}
 @end