Bläddra i källkod

1.视频372M上传成功

huangxiaodong 2 år sedan
förälder
incheckning
18420e13f4

+ 26 - 11
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileManager/uploadFileManager.m

@@ -62,7 +62,7 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
                         
                         if(curModel.curUploadStateType != uploadStateDone){
                             NSString*videoPathStr = [cachesFileManager getFilePathWithName:curModel.filename type:uploadFileTypeVideo];
-                            curModel.videoData = [NSData dataWithContentsOfFile:videoPathStr];
+                            //curModel.videoData = [NSData dataWithContentsOfFile:videoPathStr];
                         }
                     }
                     
@@ -102,7 +102,9 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
             curModel.curUploadFileType = uploadFileTypeVideo;
             [cachesFileManager getFileNameWithContent:curModel.videoData fileName:curModel.filename type:uploadFileTypeVideo];
             
+            
             curModel.totalBytes = [model.videoData length];
+            curModel.videoData = [NSData new];//视频文件存储到文件后内存清空
             
             NSString *imgName1 = [curModel.filename stringByReplacingOccurrencesOfString:@"." withString:@"_"];
             curModel.videoFirstImageName = [[NSString alloc] initWithFormat:@"%@.png",imgName1];
@@ -165,9 +167,19 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
     }
     
     NSMutableArray *curArr = totalArr[0];
-    NSArray *UploadArr = [curArr subarrayWithRange:NSMakeRange(0, _fileModelDataArr.count-1)];
-    [_fileModelDataArr removeAllObjects];
-    [_fileModelDataArr addObjectsFromArray:UploadArr];
+    
+    for (int i=0; i<_fileModelDataArr.count; i++) {
+       uploadFileDataModel *bg_mod  = _fileModelDataArr[i];
+
+       for (uploadFileDataModel *data_mod in curArr) {
+           if([data_mod.filename isEqualToString:bg_mod.filename]){
+               bg_mod.bg_id = data_mod.bg_id;
+               //HLog(@"bg_id:%@",data_mod.bg_id);
+               break;
+           }
+       }
+   }
+    
     [self beginUploadFileFun];
 }
 
@@ -178,6 +190,10 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
     
     _curUploadFileDataModel = _fileModelDataArr.firstObject;
     
+    if(!_curUploadFileDataModel){
+        return;
+    }
+    
     [[NSNotificationCenter defaultCenter] postNotificationName:uploadFileBeginNotification object:_curUploadFileDataModel];
 }
 
@@ -282,11 +298,7 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
 
 - (void)uploadFileDoneFun
 {
-    long totalSizeByte = [_curUploadFileDataModel.imageData length];
-    
-    if(_curUploadFileDataModel.curUploadFileType == uploadFileTypeVideo){
-        totalSizeByte = [_curUploadFileDataModel.videoData length];
-    }
+    long totalSizeByte = _curUploadFileDataModel.totalBytes;
     
     [self changeUploadFileState:uploadStateDone withDidUploadBytes:totalSizeByte withModel:_curUploadFileDataModel complete:^(BOOL isSuccess) {
         [self->_fileModelDataArr removeObject:self->_curUploadFileDataModel];
@@ -336,8 +348,11 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
     complete(isSuc);
     
     //继续下一个
-    [_fileModelDataArr removeObject:_curUploadFileDataModel];
-    [self beginUploadFileFun];
+    if(_fileModelDataArr){
+        [_fileModelDataArr removeObject:_curUploadFileDataModel];
+        [self beginUploadFileFun];
+    }
+    
 }
 
 @end

+ 111 - 23
创维盒子/双子星云手机/CloudPlayer/PlayerViewController+otherDelegate.mm

@@ -8,6 +8,7 @@
 #import "PlayerViewController+otherDelegate.h"
 #import "RCCommandHelp.h"
 #import "couldPhoneBaseInfoModel.h"
+#import "cachesFileManager.h"
 
 @implementation PlayerViewController (otherDelegate)
 
@@ -60,6 +61,7 @@
                     status = [[NSString  alloc] initWithFormat:@"%@",status];
                 }
                 
+                //if(1)
                 if([status isEqualToString:@"1"])
                 {
                     //[self tryAgainApplyUploadFun];
@@ -81,11 +83,11 @@
                                 fileLengthNum = data[@"fileLength"];
                             }
                             
-                            [[uploadFileManager shareInstance] changeUploadFileState:uploadStateUploading withDidUploadBytes:[fileLengthNum integerValue] withModel:self.curUploadFileDataMod complete:^(BOOL isSuccess) {
-                                
-                            }];
+                        //    [[uploadFileManager shareInstance] changeUploadFileState:uploadStateUploading withDidUploadBytes:[fileLengthNum integerValue] withModel:self.curUploadFileDataMod complete:^(BOOL isSuccess) {
+                        //
+                        //    }];
                             
-                            if([fileLengthNum integerValue] == [self.AllFileData length]){
+                            if([fileLengthNum integerValue] == self.curUploadFileDataMod.totalBytes){
                                 self.taskUid = nil;
                                 
                                 NSMutableArray *delArr = [NSMutableArray new];
@@ -104,25 +106,12 @@
                                 return;
                             }
                             
-                            self.cutFileDataArr = [self fileCutPartsBy:self.AllFileData withDidUpLoadSize:[fileLengthNum integerValue]];
-                            
-                            if(!self.cutFileDataArr){
-                                [self clearUploadFileDataFun];
-                                [[uploadFileManager shareInstance] uploadFileFailFun];
-                                
-                                self.taskUid = nil;
-                                
-                                mainBlock(^{
-                                    [[iToast makeText:NSLocalizedString(@"File_upload_fail",nil)] show];
-                                });
-                                HLog(@"hxd fail 上传任务异常终止")
-                                return;
+                            if(self.curUploadFileDataMod.curUploadFileType == uploadFileTypeImage){
+                                [self beginGotoUploadImageFun:fileLengthNum];
+                            }
+                            else{
+                                [self beginGotoUploadVidelFun:fileLengthNum];
                             }
-                            
-                            
-                            
-                            //答复的taskUid 跟申请的一致 开发发送内容
-                            [self upLoadFileFun];
                         }
                     }
                    
@@ -140,6 +129,105 @@
     }
 }
 
+
+#pragma mark 图片上传
+-(void)beginGotoUploadImageFun:(NSNumber*)fileLengthNum{
+    
+    self.cutFileDataArr = [self fileCutPartsBy:self.AllFileData withDidUpLoadSize:[fileLengthNum integerValue]];
+    
+    if(!self.cutFileDataArr){
+        [self clearUploadFileDataFun];
+        [[uploadFileManager shareInstance] uploadFileFailFun];
+        
+        self.taskUid = nil;
+        
+        mainBlock(^{
+            [[iToast makeText:NSLocalizedString(@"File_upload_fail",nil)] show];
+        });
+        HLog(@"hxd fail 上传任务异常终止")
+        return;
+    }
+    
+    //答复的taskUid 跟申请的一致 开发发送内容
+    [self upLoadFileFun];
+}
+
+
+#pragma mark 视频上传
+//每次从文件重新切一片 传一片
+-(void)beginGotoUploadVidelFun:(NSNumber*)fileLengthNum{
+    
+//    NSData *data = [self cutVideoFileFunAtIndex:0];
+//    HLog(@"data leng:%ld",[data length]);
+//    return;
+    
+    NSString*videoPathStr = [cachesFileManager getFilePathWithName:self.curUploadFileDataMod.filename type:uploadFileTypeVideo];
+    self.AllFileData = [NSData dataWithContentsOfFile:videoPathStr];
+    
+    self.cutFileDataArr = [self fileCutPartsBy:self.AllFileData withDidUpLoadSize:[fileLengthNum integerValue]];
+    
+    if(!self.cutFileDataArr){
+        [self clearUploadFileDataFun];
+        [[uploadFileManager shareInstance] uploadFileFailFun];
+        
+        self.taskUid = nil;
+        
+        mainBlock(^{
+            [[iToast makeText:NSLocalizedString(@"File_upload_fail",nil)] show];
+        });
+        HLog(@"hxd fail 上传任务异常终止")
+        return;
+    }
+    
+    //答复的taskUid 跟申请的一致 开发发送内容
+    [self upLoadFileFun];
+}
+
+#pragma mark 分段读视频文件
+-(NSData*)cutVideoFileFunAtIndex:(NSUInteger)dataIndex{
+    NSString *filePath = [cachesFileManager getFilePathWithName:self.curUploadFileDataMod.filename type:uploadFileTypeVideo]; // 文件路径
+    
+    NSFileManager *manager0 = [NSFileManager defaultManager];
+    if(![manager0 fileExistsAtPath:filePath]) {
+     
+        return [NSData new];
+    }
+    
+    NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:filePath]; // 创建文件句柄
+      
+    // 设置分段读取的大小,这里以每次读取1KB为例
+    const NSUInteger chunkSize = 20 * 1024 *1024;
+    NSMutableData *data = [NSMutableData data];
+    
+    if (fileHandle) {
+        
+        // 读取文件的分段数据到某个位置
+        if(dataIndex > 0){
+            [fileHandle seekToFileOffset:dataIndex];
+        }
+        
+        if ([fileHandle seekToEndOfFile] >= [data length]) {
+            // 读取文件的分段数据
+            NSData* chunk = [fileHandle readDataOfLength:chunkSize];
+            if (chunk) {
+                [data appendData:chunk];
+            }
+        }
+        else{
+            [data appendData:[fileHandle readDataToEndOfFile]];
+        }
+        
+        // 在这里可以对文件内容进行处理
+        // ...
+        
+        // 关闭文件句柄
+        [fileHandle closeFile];
+    }
+    
+    return data;
+}
+
+
 - (void)upLoadFileFunServiceResponseFun:(NSDictionary *)dataDict
 {
     //{"type":"uploadFileRandomRet","data":{"progress":"9\/10","filePath":"/sdcard/Download/IMG_0036.JPG","status":"0","msg":"success"}}
@@ -183,7 +271,7 @@
         self.taskUid = [iTools getTaskUidStr];
         self.fileName = self.curUploadFileDataMod.filename;
         if(self.curUploadFileDataMod.curUploadFileType == uploadFileTypeVideo){
-            self.AllFileData = self.curUploadFileDataMod.videoData;
+            //self.AllFileData = self.curUploadFileDataMod.videoData;
         }
         else{
             self.AllFileData = self.curUploadFileDataMod.imageData;