ソースを参照

1.音频缓存无网络播放--进行中

huangxiaodong 1 ヶ月 前
コミット
d898637a76

+ 2 - 0
创维盒子/code/Class/Set/previewFile/model/NASFileAudioModel.h

@@ -19,6 +19,8 @@ NS_ASSUME_NONNULL_BEGIN
 
 //自定义
 @property (nonatomic, assign) BOOL isSelectType;
+@property (nonatomic, assign) BOOL isDidCacheType;//是否有缓存
+@property (nonatomic, assign) BOOL isOffLineType;//是否离线状态
 @end
 
 @protocol NASFileAudioDataModel;

+ 39 - 1
创维盒子/code/Class/Set/previewFile/previewAudioOrDocumentViewController.m

@@ -458,7 +458,7 @@
 {
     NSInteger row = indexPath.row;
     if(row < _curNASFileAudioMod.data.list.count){
-        
+                
 //        NASFileAudioDataModel*dataModel =  _curNASFileAudioMod.data.list[row];
 //        videoPlayByAVPlayerViewController *vc = [videoPlayByAVPlayerViewController new];
 //        NASFilePicDataArrModel *VideoDataMode = [NASFilePicDataArrModel new];
@@ -470,6 +470,12 @@
 //        [self.navigationController pushViewController:vc animated:YES];
         
         NASFileAudioDataModel*dataModel =  _curNASFileAudioMod.data.list[row];
+        
+        if(dataModel.isOffLineType && !dataModel.isDidCacheType){
+            [self showPlayOffAndNotCacheLineFile];
+            return;
+        }
+        
         audioPlayerViewController * vc = [audioPlayerViewController new];
         vc.isfirstEnterType = YES;
         vc.outSideDataModel = dataModel;
@@ -823,6 +829,18 @@
             _curNASFileAudioMod = [[NASFileAudioModel alloc] initWithDictionary:DataDict error:nil];
         }
         
+        //没有网络
+        //if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable)
+        {
+            for (NASFileAudioDataModel*model in _curNASFileAudioMod.data.list) {
+                model.isOffLineType = YES;
+                //判断是否有缓存
+                BOOL isDidCacheType =  [[audioPlayListManager shareManager] checkFileToDownloadDonewithPath:model.path];
+                model.isDidCacheType = isDidCacheType;
+                HLog(@"isDidCacheType: %d-%@",isDidCacheType,model.name)
+            }
+        }
+        
         [self getFileListFun:NO];
         [self queryShareSwitchFunFun];
     }
@@ -1222,4 +1240,24 @@
     
 }
 
+#pragma mark 文件未缓存提示弹框
+- (void)showPlayOffAndNotCacheLineFile
+{
+    //KWeakSelf
+    ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"File_upload_Record_clear_Tip_title",nil)
+                                                                                     msg:NSLocalizedString(@"audio_not_Cache_Tip",nil)
+                                                                                imageStr:@""
+                                                                             cancelTitle:NSLocalizedString(@"common_I_know",nil)
+                                                                                 okTitle:@""
+                                                                        isOkBtnHighlight:NO
+                                                                              didClickOk:^{
+    } didClickCancel:^{
+        
+    }];
+    nextVC.modalPresentationStyle = UIModalPresentationCustom;
+
+    [self presentViewController:nextVC animated:YES completion:^{
+        nextVC.view.superview.backgroundColor = [UIColor clearColor];
+    }];
+}
 @end

+ 6 - 1
创维盒子/code/Class/Set/uploadFile/downLoadFile/view/downLoadPreViewCell.m

@@ -241,10 +241,14 @@
         rightStr = [[NSString alloc] initWithFormat:@"\n%@",dateStr];
     }
     
+    //处理音频 无网络 读取缓存的情况
+    if (_curNASFileAudioDataModel.isOffLineType && !_curNASFileAudioDataModel.isDidCacheType) {
+        titleLabel.textColor = [UIColor hwColor:@"#666666" alpha:1.0];
+    }
+    
     NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
     
     NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length);
-    [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#666666" alpha:1.0] range:redRange];
     [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
     // 设置行间距
     NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
@@ -254,6 +258,7 @@
     
     
     titleLabel.attributedText = noteStr;
+    
 }
 
 - (void)setCurNASFileAndFolderDataModel:(NASFileAndFolderDataModel *)curNASFileAndFolderDataModel

+ 4 - 1
创维盒子/code/NAS/recenFile/audioPlayListManager.h

@@ -36,8 +36,11 @@ NS_ASSUME_NONNULL_BEGIN
 /**  更新下载完成 */
 - (void)changeFileToDonewith:(NSString*)url;
 
-/**  检测是否下载完成 */
+/**  检测是否下载完成 URL 需要解码的 */
 - (NSString*)checkFileToDownloadDonewith:(NSString*)url;
+
+/**  检测是否下载完成 path  不需要解码的 */
+- (BOOL)checkFileToDownloadDonewithPath:(NSString*)path;
 @end
 
 NS_ASSUME_NONNULL_END

+ 31 - 0
创维盒子/code/NAS/recenFile/audioPlayListManager.m

@@ -356,4 +356,35 @@
     
     return @"";
 }
+
+/**  检测是否下载完成 path  不需要解码的 */
+- (BOOL)checkFileToDownloadDonewithPath:(NSString*)path
+{
+    NSString *filePath = path;//[path lastPathComponent];
+    for (lastFileModel*model in self.audioPlayListArr) {
+        if([model.path isEqualToString:filePath]){
+            if (model.isDownDoneType) {
+                if(model.localPath){
+                    NSString *curFilePath  = [[audioPlayListManager shareManager] getAudioCacheFullPathBy:model.name];
+                    
+                    // 创建NSFileManager实例
+                    NSFileManager *fileManager = [NSFileManager defaultManager];
+              
+                    // 使用fileExistsAtPath方法检查文件是否存在
+                    BOOL fileExists = [fileManager fileExistsAtPath:curFilePath];
+              
+                    if (fileExists) {
+                        return  YES;
+                    } else {
+                        return NO;
+                    }
+                }
+            }
+            
+            break;
+        }
+    }
+    
+    return NO;
+}
 @end

+ 2 - 0
创维盒子/code/zh-Hans.lproj/Localizable.strings

@@ -679,3 +679,5 @@
 "alert_install_TV_msg_1"      = "安装成功后可以到“TV-我的-我的应用”查看,本次安装";
 "alert_install_TV_msg_2"      = "个文件预计需要";
 "alert_install_TV_msg_3"      = "秒。";
+"audio_not_Cache_Tip"      = "这首音频未缓存不能离线听,\n请连接网络后重试。";
+