瀏覽代碼

1.文件上传拷贝视频到内存

huangxiaodong 1 年之前
父節點
當前提交
64a00610fe

+ 4 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileManager/cachesFileManager.h

@@ -19,11 +19,15 @@ NS_ASSUME_NONNULL_BEGIN
 @interface cachesFileManager : NSObject
 //获取文件路径(没有的话创建)
 + (NSString *)getCreateFilePath:(NSString *)path;
++ (BOOL)checkFileIsSaveState:(NSString *)fileName withType:(uploadFileType)type;
 
 //获取资源名字并且保存资源
 + (NSString *)getFileNameWithContent:(id)content fileName:(NSString*)fileName type:(uploadFileType)type;
 //获取资源路径
 + (NSString *)getFilePathWithName:(NSString *)name type:(uploadFileType)type;
+
++ (BOOL)copyVideoItemAtPath:(NSString *)Path fileName:(NSString *)fileName error:(NSError *__autoreleasing *)error;
+
 //删除文件
 + (BOOL)removeItemAtPath:(NSString *)fileName type:(uploadFileType)type error:(NSError *__autoreleasing *)error;
 @end

+ 23 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileManager/cachesFileManager.m

@@ -20,6 +20,15 @@
     return path;
 }
 
+
+#pragma mark - 获取文件夹(没有的话创建)
++ (BOOL)checkFileIsSaveState:(NSString *)fileName withType:(uploadFileType)type
+{
+    
+    NSString * path = [cachesFileManager getFilePathWithName:fileName type:type];
+    return [[NSFileManager defaultManager] fileExistsAtPath:path];
+}
+
 //获取资源名字并且保存资源
 + (NSString *)getFileNameWithContent:(id)content fileName:(NSString*)fileName type:(uploadFileType)type
 {
@@ -125,4 +134,18 @@
     
     return success;
 }
+
++ (BOOL)copyVideoItemAtPath:(NSString *)Path fileName:(NSString *)fileName error:(NSError *__autoreleasing *)error {
+    NSString *curPath = [cachesFileManager getFilePathWithName:fileName type:uploadFileTypeVideo];
+            
+    BOOL success = [[NSFileManager defaultManager] copyItemAtPath:Path toPath:curPath error:error];
+    if (success) {
+        // 文件删除成功
+    } else {
+        // 文件删除失败
+        NSLog(@"删除文件失败:%@-----%@",fileName,error);
+    }
+    
+    return success;
+}
 @end

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

@@ -134,21 +134,21 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
             }];
 
             //真正的视频数据
-            PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
-            options.version = PHVideoRequestOptionsVersionOriginal;
-            [[PHImageManager defaultManager] requestAVAssetForVideo:curModel.asset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
-                if ([asset isKindOfClass:[AVURLAsset class]]) {
-                    
-                    AVURLAsset* urlAsset = (AVURLAsset*)asset;
-                    NSData *videoData = [NSData dataWithContentsOfURL:urlAsset.URL];
-               
-                    if (videoData) {
-                        curModel.videoData = videoData;
-                        [cachesFileManager getFileNameWithContent:curModel.videoData fileName:curModel.filename type:uploadFileTypeVideo];
-                        curModel.videoData = nil;
-                    }
-             }
-            }];
+//            PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
+//            options.version = PHVideoRequestOptionsVersionOriginal;
+//            [[PHImageManager defaultManager] requestAVAssetForVideo:curModel.asset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
+//                if ([asset isKindOfClass:[AVURLAsset class]]) {
+//
+//                    AVURLAsset* urlAsset = (AVURLAsset*)asset;
+//                    NSData *videoData = [NSData dataWithContentsOfURL:urlAsset.URL];
+//
+//                    if (videoData) {
+//                        curModel.videoData = videoData;
+//                        [cachesFileManager getFileNameWithContent:curModel.videoData fileName:curModel.filename type:uploadFileTypeVideo];
+//                        curModel.videoData = nil;
+//                    }
+//             }
+//            }];
 
         }
         else{
@@ -272,12 +272,10 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
         
     }
     else{
-        NSString*pathStr = [cachesFileManager getFilePathWithName:_curUploadFileDataModel.filename type:uploadFileTypeVideo];
-        NSData *curdata = [NSData dataWithContentsOfFile:pathStr];
+        //NSString*pathStr = [cachesFileManager getFilePathWithName:_curUploadFileDataModel.filename type:uploadFileTypeVideo];
+        
+        if([cachesFileManager checkFileIsSaveState:_curUploadFileDataModel.filename withType:uploadFileTypeVideo]){
         
-        if(curdata && curdata.length >0){
-            curdata = nil;
-            
             [[NSNotificationCenter defaultCenter] postNotificationName:uploadFileBeginNotification object:_curUploadFileDataModel];
             return;
         }
@@ -330,10 +328,13 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
             if ([asset isKindOfClass:[AVURLAsset class]]) {
                 
                 AVURLAsset* urlAsset = (AVURLAsset*)asset;
-                NSData *videoData = [NSData dataWithContentsOfURL:urlAsset.URL];
+                
+                BOOL isSuc = [cachesFileManager copyVideoItemAtPath:[urlAsset.URL path] fileName:_curUploadFileDataModel.filename error:nil];
+                
+                //NSData *videoData =  [NSData dataWithContentsOfURL:urlAsset.URL];
            
-                if (videoData) {
-                    self->_curUploadFileDataModel.videoData = videoData;
+                if (isSuc) {
+                    //self->_curUploadFileDataModel.videoData = videoData;
                     [weakSelf  afterGetVideoDataFun];
                 }
                 else{
@@ -341,7 +342,6 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
                 }
          }
         }];
-
     }
 }
 

+ 7 - 5
创维盒子/双子星云手机/Class/Set/uploadFile/uploadImageOrVideoViewController.m

@@ -501,14 +501,16 @@
                 if ([asset isKindOfClass:[AVURLAsset class]]) {
                     
                     AVURLAsset* urlAsset = (AVURLAsset*)asset;
-                    NSData *videoData = [NSData dataWithContentsOfURL:urlAsset.URL];
-//                        NSNumber *size;
-//                        [urlAsset.URL getResourceValue:&size forKey:NSURLFileSizeKey error:nil];
-//                        NSLog(@"size is %f",[size floatValue]/(1024.0*1024.0));
+        
+                    //NSData *videoData = [NSData dataWithContentsOfURL:urlAsset.URL];
+                    NSNumber *size;
+                    [urlAsset.URL getResourceValue:&size forKey:NSURLFileSizeKey error:nil];
+                    //NSLog(@"size is %f",[size floatValue]/(1024.0*1024.0));
                  
                     
                     //model.videoData = videoData;
-                    model.totalBytes = [videoData length];
+                    //model.totalBytes = [videoData length];
+                    model.totalBytes = size.longLongValue;
                     [self setDataToBottomViewFun];
              }
             }];