浏览代码

1.音频播放修改

huangxiaodong 1 年之前
父节点
当前提交
7f9775e6c2
共有 1 个文件被更改,包括 31 次插入9 次删除
  1. 31 9
      创维盒子/双子星云手机/Class/Set/previewFile/audioPlayerViewController.m

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

@@ -13,6 +13,8 @@
 
 @interface audioPlayerViewController ()<DFPlayerDelegate,DFPlayerDataSource>
 
+@property (nonatomic, assign) BOOL isOlnyOneType;
+
 @property (nonatomic, strong) UIImageView*bgImageView;
 
 @property (nonatomic, strong) NSMutableArray<DFPlayerModel *> *dataArray;
@@ -23,6 +25,7 @@
 - (void)viewDidLoad {
     [super viewDidLoad];
     // Do any additional setup after loading the view.
+    _isOlnyOneType = YES;
     
     [self.toolBar setHidden:YES];
     [self.navigationBar setHidden:YES];
@@ -137,7 +140,9 @@
     
     //下一首按钮
     UIButton * nextBtn = [mgr df_nextBtnWithFrame:CGRectZero image:nextImage superView:self.view block:nil];
-    nextBtn.hidden = YES;
+    if(_isOlnyOneType){
+        nextBtn.hidden = YES;
+    }
     [nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
         make.top.equalTo(curSlider.mas_bottom).offset(20);
         make.height.mas_equalTo(30);
@@ -147,7 +152,10 @@
     
     //上一首按钮
     UIButton * lastBtn = [mgr df_lastBtnWithFrame:CGRectZero image:lastImage superView:self.view block:nil];
-    lastBtn.hidden = YES;
+    if(_isOlnyOneType){
+        lastBtn.hidden = YES;
+    }
+    
     [lastBtn mas_makeConstraints:^(MASConstraintMaker *make) {
         make.top.equalTo(curSlider.mas_bottom).offset(20);
         make.height.mas_equalTo(30);
@@ -162,14 +170,19 @@
     
     for (int i = 0; i < _audioOutSidedataArray.count; i++) {
         
-        if(i!=_index){
-            continue;
+        if(_isOlnyOneType){
+            if(i!=_index){
+                continue;
+            }
         }
         
+        
         NASFileAudioDataModel *yourModel = _audioOutSidedataArray[i];
         DFPlayerModel *model = [[DFPlayerModel alloc] init];
         model.audioId = i;//****重要。AudioId从0开始,仅标识当前音频在数组中的位置。
-        
+        if(_isOlnyOneType){
+            model.audioId = 0;
+        }
         NSString *filePath = yourModel.path;
         NSString *urlStr = ksharedAppDelegate.NASFileByBoxService;
         
@@ -254,7 +267,7 @@
 
 //缓冲进度代理
 - (void)df_player:(DFPlayer *)player bufferProgress:(CGFloat)bufferProgress{
-    HLog(@"缓冲进度代理");
+    HLog(@"缓冲进度代理:%f",bufferProgress);
 }
 
 //播放进度代理
@@ -316,9 +329,18 @@
 
 - (void)playAudioFun
 {
-    if(_index < self.dataArray.count){
-        DFPlayerModel *model = self.dataArray[_index];
-        [[DFPlayer sharedPlayer] df_playWithAudioId:model.audioId];
+    if(_isOlnyOneType){
+        if( self.dataArray.count == 1){
+            DFPlayerModel *model = self.dataArray.firstObject;
+            [[DFPlayer sharedPlayer] df_playWithAudioId:model.audioId];
+        }
     }
+    else{
+        if(_index < self.dataArray.count){
+            DFPlayerModel *model = self.dataArray[_index];
+            [[DFPlayer sharedPlayer] df_playWithAudioId:model.audioId];
+        }
+    }
+    
 }
 @end