Pārlūkot izejas kodu

1.下载逻辑修改

huangxiaodong 1 gadu atpakaļ
vecāks
revīzija
fb9a37b690

+ 5 - 2
创维盒子/双子星云手机/AppDelegate/SceneDelegate.m

@@ -98,7 +98,6 @@
         ksharedAppDelegate.window = self.window;
         
         //冷启动
-        [boxDownloadFileManager shareInstance];
         if(connectionOptions.URLContexts != nil){
             _session = session;
             _connectionOptions = connectionOptions;
@@ -259,6 +258,9 @@
         return;
     }
     
+    //下载配置先处理
+    [boxDownloadFileManager shareInstance];
+    
     if(_curPlayerVC){
         //[_curPlayerVC disconnectVideoServer];
         
@@ -777,7 +779,7 @@
     [[backupsFileManager shareInstance] suspendBackupsFileFun];
     
     //frp的下载
-    //[YCDownloadManager pauseAllDownloadTask];
+    [YCDownloadManager pauseAllDownloadTask];
     
     NSString *uid =[connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn;
     if(uid){
@@ -786,6 +788,7 @@
     else{
         uid = @"";
     }
+    
     [YCDownloadManager updateUid:uid];
 }
 

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

@@ -137,7 +137,7 @@
     
     //下一首按钮
     UIButton * nextBtn = [mgr df_nextBtnWithFrame:CGRectZero image:nextImage superView:self.view block:nil];
-    
+    nextBtn.hidden = YES;
     [nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
         make.top.equalTo(curSlider.mas_bottom).offset(20);
         make.height.mas_equalTo(30);
@@ -147,7 +147,7 @@
     
     //上一首按钮
     UIButton * lastBtn = [mgr df_lastBtnWithFrame:CGRectZero image:lastImage superView:self.view block:nil];
-    
+    lastBtn.hidden = YES;
     [lastBtn mas_makeConstraints:^(MASConstraintMaker *make) {
         make.top.equalTo(curSlider.mas_bottom).offset(20);
         make.height.mas_equalTo(30);
@@ -205,6 +205,8 @@
 //        fileUrl = @"http://transfertest.armclouding.com:10001/getFile?path=/storage/6C07-E638/miniType/%E9%9F%B3%E9%A2%91%E6%A0%BC%E5%BC%8Fing/jiajiaeeyinyue.mp3";
         
         //fileUrl = @"http://transfertest.armclouding.com:21025/getFiles/L3N0b3JhZ2UvZW11bGF0ZWQvMC9NdXNpYy9vYmoubXAz";
+        //fileUrl = @"http://transfertest.armclouding.com:21025/getFiles/L3NkY2FyZC9NdXNpYy9vYmoubXAz";
+        
         
 //        fileUrl  = [fileUrl stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
         
@@ -252,14 +254,12 @@
 
 //缓冲进度代理
 - (void)df_player:(DFPlayer *)player bufferProgress:(CGFloat)bufferProgress{
-    //[self congfigCell:player.currentAudioModel.audioId
-      //detailTextLabel:[NSString stringWithFormat:@"正在缓冲%lf",bufferProgress]];
+    HLog(@"缓冲进度代理");
 }
 
 //播放进度代理
 - (void)df_player:(DFPlayer *)player progress:(CGFloat)progress currentTime:(CGFloat)currentTime{
-//    [self congfigCell:player.currentAudioModel.audioId
-//      detailTextLabel:[NSString stringWithFormat:@"当前进度%lf--当前时间%.0f",progress,currentTime]];
+    HLog(@"音频播放进度代理");
 }
 
 //状态信息代理
@@ -302,7 +302,7 @@
 - (void)viewDidDisappear:(BOOL)animated
 {
     [super viewDidDisappear:animated];
-    [[DFPlayer sharedPlayer] df_pause];
+    [[DFPlayer sharedPlayer] df_deallocPlayer];
 }
 
 -(void)setTitleFunByIndex

+ 2 - 1
创维盒子/双子星云手机/Class/Set/uploadFile/receiveView/boxDownloadFileRecordCell.h

@@ -7,7 +7,8 @@
 
 #import <UIKit/UIKit.h>
 #import "queryOneShareModel.h"
-#import "YCDownloadSession.h"
+//#import "YCDownloadSession.h"
+#import <YCDownloadSession.h>
 NS_ASSUME_NONNULL_BEGIN
 
 @interface boxDownloadFileRecordCell : UITableViewCell<YCDownloadItemDelegate>

+ 7 - 40
创维盒子/双子星云手机/Class/Set/uploadFile/receiveView/boxDownloadFileRecordCell.m

@@ -35,14 +35,7 @@
     
     if (self)
     {
-        //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeIng:) name:SGDownloadTaskExeing object:nil];
-
-//        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeEnd:) name:SGDownloadTaskExeEnd object:nil];
-//
-//        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeError:) name:SGDownloadTaskExeError object:nil];
-
-        //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeSupend:) name:SGDownloadTaskExeSuspend object:nil];
-        
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskDownloadingNoti:) name:kDownloadTaskDownloadingNoti object:nil];
         [self drawView];
     }
     
@@ -642,45 +635,19 @@
     });
 }
 
-- (void)downloadTaskExeIng:(NSNotification *)notification
+#pragma mark 下载通知
+- (void)downloadTaskDownloadingNoti:(NSNotification *)notification
 {
-    //test code
-//    NSMutableArray *allOperation = [[SGDownloadManager shareManager] getAllOperation];
-//    NSInteger index = 0;
-//    for (SGDownloadOperation *model in allOperation){
-//        HLog(@"%ld  %ld %@",index,model.downloadState,model.fileName);
-//        index++;
-//    }
-    
+    YCDownloadItem *item = notification.object;
+    if(!item)return;
     
-    SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
-    
-    NSString * urlString = [model.url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
-    //HLog(@"%@\n %@",urlString,_curShareFileDataModel.fileUrl);
-    if (![urlString isEqualToString:_curShareFileDataModel.fileUrl]
-        ||model.totalSize == model.currentSize) { // 不是这一个任务
+    if (item.downloadStatus != YCDownloadStatusDownloading) {
         return;
     }
     
-    if(_curShareFileDataModel
-       &&(_curShareFileDataModel.downloadBoxStateType == downloadBoxStateDone
-       ||_curShareFileDataModel.downloadBoxStateType == downloadBoxStateFail)
-       ){
-        return;
-    }
-    
-    _curShareFileDataModel.downloadBoxStateType = downloadBoxStateDownloadloading;
-    _curShareFileDataModel.currentSize = model.currentSize;
-    _curShareFileDataModel.curTimeInterval = [[NSDate date] timeIntervalSince1970];
-    
-    mainBlock(^{
-        [self updateDataDownloadingBy:self->_curShareFileDataModel];
-    });
-    HLog(@"下载中");
+    [self downloadItem:item downloadedSize:item.downloadedSize totalSize:item.fileSize];
 }
 
-
 #pragma mark 下载代理
 - (void)downloadItemStatusChanged:(YCDownloadItem *)item {
     //[self setDownloadStatus:item.downloadStatus];

+ 38 - 23
创维盒子/双子星云手机/Class/Set/uploadFile/receiveView/receiveDownloadRecordTableView.m

@@ -139,30 +139,43 @@
             cell.curShareFileDataModel = model;
             
             cell.isEditType = _isEditType;
-
-            NSArray *allDownItemArr = [YCDownloadManager downloadList];
-            if (allDownItemArr.count > row && section == 0) {
-                for (YCDownloadItem *item in allDownItemArr) {
-                    if (item.downloadStatus != YCDownloadStatusFinished) {
-                        //解码
-                        NSString * urlString = [item.downloadURL stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-                        
-                        HLog(@"%@\n%@",urlString,model.fileUrl);
-                        
-                        if([urlString isEqualToString:model.fileUrl]){
-                            cell.item = item;
-                            item.delegate = cell;
-                            break;
-                        }
-                    }
-                }
-
-            }
             
-            if(cell.curShareFileDataModel.downloadBoxStateType == downloadBoxStateDone){
-                cell.item.delegate = nil;
-                cell.item = nil;
-            }
+//            NSString *urlString = model.fileUrl;
+//            NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+//            
+//            NSArray *urlallDownItemArr = [YCDownloadManager itemsWithDownloadUrl:requestURLEncodedString];
+//            HLog(@"hxd urlallDownItemArr count: %ld --- %@",urlallDownItemArr.count,requestURLEncodedString);
+//            if (urlallDownItemArr.count > 0 && section == 0 && model.downloadBoxStateType != downloadBoxStateDone) {
+//                if (urlallDownItemArr.count == 1) {
+//                    YCDownloadItem * item = urlallDownItemArr.firstObject;
+//                    cell.item = item;
+//                    item.delegate = cell;
+//                    HLog(@"hxd downloadStatus:%ld  %@",item.downloadStatus,item.downloadURL);
+//                    if(item.downloadStatus == YCDownloadStatusFinished){
+//                        [[NSNotificationCenter defaultCenter] postNotificationName:kDownloadTaskFinishedNoti object:item];
+//                    }
+//                }
+//                else{
+//                    for (YCDownloadItem *item in urlallDownItemArr) {
+//                        HLog(@"hxd downloadStatus:%ld  %@",item.downloadStatus,item.downloadURL);
+//                        if (item.downloadStatus != YCDownloadStatusFinished
+//                            && item.downloadStatus != YCDownloadStatusFailed
+//                            //&& model.downloadBoxStateType == downloadBoxStateDownloadloading
+//                            ) {
+//                            cell.item = item;
+//                            item.delegate = cell;
+//                            break;
+//                        }
+//                    }
+//                }
+//                
+//            }
+//            else{
+////                cell.item.delegate = nil;
+////                cell.item = nil;
+//            }
+            
+            
             
             if(_isEditType){
                 if([_selectModelArr containsObject:model]){
@@ -656,6 +669,8 @@
 #pragma mark 下载完成
 - (void)downloadTaskFinishedNoti:(NSNotification *)notification
 {
+    HLog(@"下载完成或者失败");
+    
     YCDownloadItem *item = notification.object;
     KWeakSelf
     if (item.downloadStatus == YCDownloadStatusFinished) {

+ 112 - 30
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileManager/boxDownloadFileManager.m

@@ -44,6 +44,7 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
     config.saveRootPath = path;
     //config.uid = @"100006";
     config.uid = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn;
+    HLog(@"%@",config.uid);
     config.maxTaskCount = 1;
     config.taskCachekMode = YCDownloadTaskCacheModeDefault;//YCDownloadTaskCacheModeKeep;
     config.launchAutoResumeDownload = NO;
@@ -69,6 +70,47 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
     }
 }
 
+#pragma mark 删除多余的任务 比如数据删除了 但是任务还在
+- (void)checkDownloadTaskFun{
+    NSArray *allDownItemArr = [YCDownloadManager downloadList];
+   
+    NSArray* downloadingArr = nil;
+    NSArray* downloadingFail = nil;
+    if(_databaseArr && _databaseArr.count == 3){
+        downloadingArr = _databaseArr[0];
+        downloadingFail = _databaseArr[2];
+    }
+    
+    for (YCDownloadItem *item in allDownItemArr) {
+        
+        BOOL isNeedStopType = YES;
+        
+        //解码
+        NSString * urlString = [item.downloadURL stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+        
+        if(downloadingArr && downloadingArr.count > 0){
+            for (ShareFileDataModel*dataModel in downloadingArr) {
+                if([urlString isEqualToString:dataModel.fileUrl]){
+                    isNeedStopType = NO;
+                }
+            }
+        }
+        
+        if(downloadingFail && downloadingFail.count > 0){
+            for (ShareFileDataModel*dataModel in downloadingFail) {
+                if([urlString isEqualToString:dataModel.fileUrl]){
+                    isNeedStopType = NO;
+                }
+            }
+        }
+        
+        if(isNeedStopType){
+            HLog(@"停止多的下载任务:%@",item.downloadURL);
+            [YCDownloadManager stopDownloadWithItem:item];
+        }
+        
+    }
+}
 
 //添加保存记录
 - (void)addBoxDownloadRecordFunBy:(NSArray*)arr complete:(custom_complete_B)complete{
@@ -134,7 +176,7 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
         _databaseArr = [NSMutableArray new];
     }
     
-    //KWeakSelf
+    KWeakSelf
     //dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
 //    NSLock *lock = [NSLock new];
 //    [lock lock];
@@ -167,6 +209,10 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
             
             [lock unlock];
             
+            if(isReGet){
+                [self checkDownloadTaskFun];
+            }
+            
             complete(self->_databaseArr);
         }];
    // [lock unlock];
@@ -229,17 +275,12 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
         
         
         //3.取消下载
-        NSArray *allDownItemArr = [YCDownloadManager downloadList];
+        NSString *urlString = dataModel.fileUrl;
+        NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+        
+        NSArray *allDownItemArr = [YCDownloadManager itemsWithDownloadUrl:requestURLEncodedString];
         for (YCDownloadItem *item in allDownItemArr) {
-            //解码
-            NSString * urlString = [item.downloadURL stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-            
-            HLog(@"%@\n%@\n%@",urlString,dataModel.fileUrl);
-
-            if([urlString isEqualToString:dataModel.fileUrl]){
-                [YCDownloadManager stopDownloadWithItem:item];
-                //break;
-            }
+            [YCDownloadManager stopDownloadWithItem:item];
         }
         
     }
@@ -384,21 +425,41 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
         }
         
         [YCDownloadManager pauseAllDownloadTask];
-        //[[SGDownloadManager shareManager] suspendAllDownloadTask];
-       
     }
-    else if(dataModel && item){//暂停指定任务
-        [YCDownloadManager pauseDownloadWithItem:item];
+    else if(dataModel){//暂停指定任务
+        NSString *urlString = dataModel.fileUrl;
+        NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+        
+        if(item && [item.downloadURL isEqualToString:requestURLEncodedString]){
+            [YCDownloadManager pauseDownloadWithItem:item];
+        }
+        else{
+            NSArray *allDownItemArr = [YCDownloadManager itemsWithDownloadUrl:requestURLEncodedString];
+        
+            if(allDownItemArr.count == 1){
+                YCDownloadItem *item = allDownItemArr.firstObject;
+                [YCDownloadManager pauseDownloadWithItem:item];
+            }
+            else{
+                for (YCDownloadItem *item in allDownItemArr) {
+                    if (item.downloadStatus == YCDownloadStatusFinished) {//这里有问题
+                        [YCDownloadManager stopDownloadWithItem:item];
+                    }
+                    else{
+                        [YCDownloadManager pauseDownloadWithItem:item];
+                    }
+                }
+            }
+            
+        }
+        
+        //2.修改状态
         if (_databaseArr && _databaseArr.count == 3) {
             NSMutableArray *downloadingArr = _databaseArr[0];
             for (ShareFileDataModel*model in downloadingArr) {
                 
                 if(model.bg_id.integerValue == dataModel.bg_id.integerValue){
                     model.downloadBoxStateType = downloadBoxStateSuspend;
-                    
-//                    NSString *urlString = model.fileUrl;
-//                    NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-//                    [[SGDownloadManager shareManager] supendDownloadWithUrl:requestURLEncodedString];
                     break;
                 }
             }
@@ -409,24 +470,45 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
 #pragma mark 重新开始下载
 - (void)reDownloadFileFunBy:(NSMutableArray*)arr withAll:(BOOL)isAllType withItem:(YCDownloadItem*)item
 {
-    //目前只允许一个下载 所以先暂停任务
-    //[[SGDownloadManager shareManager] suspendAllDownloadTask];
-    
+ 
     if(isAllType){
-        //[[SGDownloadManager shareManager] startAllDownloadTask];
         [YCDownloadManager resumeAllDownloadTask];
 
     }
     else{
-        if (item) {
-            [YCDownloadManager resumeDownloadWithItem:item];
+        
+        ShareFileDataModel* dataModel = nil;
+        if(arr && arr.count > 0){
+            dataModel = arr.firstObject;
+        }else{
+            return;
         }
+        NSString *urlString = dataModel.fileUrl;
+        NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
         
-//        for (ShareFileDataModel*model in arr) {
-//            model.downloadBoxStateType = downloadBoxStateDownloadloading;
-//            [self reDownloadFileFunBy:model];
-//            break;
-//        }
+        if (item && [item.downloadURL isEqualToString:requestURLEncodedString]) {
+            [YCDownloadManager resumeDownloadWithItem:item];
+        }
+        else
+        {
+            NSArray *allDownItemArr = [YCDownloadManager itemsWithDownloadUrl:requestURLEncodedString];
+            
+            if(allDownItemArr.count == 1){
+                YCDownloadItem *item = allDownItemArr.firstObject;
+                [YCDownloadManager resumeDownloadWithItem:item];
+            }
+            else{
+                for (YCDownloadItem *item in allDownItemArr) {
+                    if (item.downloadStatus != YCDownloadStatusFinished) {
+                        [YCDownloadManager resumeDownloadWithItem:item];
+                    }
+                    else{
+                        [YCDownloadManager stopDownloadWithItem:item];
+                    }
+                }
+            }
+            
+        }
     }
 }
 

+ 3 - 3
创维盒子/双子星云手机/CloudPlayer/PlayerViewController+downloadNasFile.m

@@ -88,7 +88,7 @@
              //
              [[NSFileManager defaultManager] removeItemAtPath:fullPath error:nil];
              if(self->curYCDownloadItem){
-                 //[YCDownloadManager stopDownloadWithItem:self->curYCDownloadItem];
+                 [YCDownloadManager stopDownloadWithItem:self->curYCDownloadItem];
                  self->curYCDownloadItem = nil;
              }
              
@@ -113,7 +113,7 @@
             //
             [[NSFileManager defaultManager] removeItemAtPath:pathStr error:nil];
             if(self->curYCDownloadItem){
-                //[YCDownloadManager stopDownloadWithItem:self->curYCDownloadItem];
+                [YCDownloadManager stopDownloadWithItem:self->curYCDownloadItem];
                 self->curYCDownloadItem = nil;
             }
         } else {
@@ -173,7 +173,7 @@
                 //
                 [[NSFileManager defaultManager] removeItemAtPath:pathStr error:nil];
                 if(self->curYCDownloadItem){
-                    //[YCDownloadManager stopDownloadWithItem:self->curYCDownloadItem];
+                    [YCDownloadManager stopDownloadWithItem:self->curYCDownloadItem];
                     self->curYCDownloadItem = nil;
                 }