Przeglądaj źródła

视频支持边下边播

zwp 5 miesięcy temu
rodzic
commit
a0f777d32e

+ 1 - 1
AIIM/Common/CommonUI/FilePreviewer.m

@@ -193,7 +193,7 @@
 #pragma mark - Private Methods - Video Preview
 
 - (void)previewVideoAtURL:(NSURL *)videoURL {
-    
+    NSLog(@"previewVideoAtURL: %@", videoURL);
     AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];
     AVPlayer *player = [AVPlayer playerWithURL:videoURL];
     playerViewController.player = player;

+ 29 - 2
AIIM/Controller/chat/chetCell/ChatMessageModel.m

@@ -121,6 +121,12 @@
     self.formatterTime = [self timeF:self.timestamp];
     // 其他自定义字段...
     self.readStatus = [self getReadStatus];
+    
+    BOOL contain = [[NSFileManager defaultManager] fileExistsAtPath:self.localurl];
+    NSString *localPath = [self checkHasLocalPath];
+    if (!contain && localPath.length) {
+        self.localurl = localPath;
+    }
 }
 
 - (void)exchangeModelWithModel:(ChatMessageModel *)model{
@@ -393,6 +399,7 @@
         if (loading) {
             loading(100);
         }
+        NSLog(@"downloadFileIfNeed 0: %@", localFileurl);
         return;
     }
     
@@ -402,9 +409,8 @@
     NSString *fileExtension = [fileName pathExtension];
     NSString *newfileName = [NSString stringWithFormat:@"%@.%@", self.msgId,fileExtension];
     documentsDirectoryURL = [documentsDirectoryURL URLByAppendingPathComponent:newfileName];
-    NSLog(@"文件本地路径:%@",documentsDirectoryURL.path);
     if ([[NSFileManager defaultManager] fileExistsAtPath:documentsDirectoryURL.path]){
-        NSLog(@"文件已经存在本地");
+        NSLog(@"downloadFileIfNeed 1: %@", documentsDirectoryURL.path);
         NSMutableDictionary *mutableDict = [self.formerMessage mutableCopy];
         NSMutableDictionary *extend = [self.formerMessage[@"extend"] mutableCopy];
         [extend setObject:documentsDirectoryURL.path forKey:@"localurl"];
@@ -503,4 +509,25 @@
     return _customFileSize;
 }
 
+- (NSString *)checkHasLocalPath {
+    NSString *localFileurl = [self.localurl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]];
+    if (self.localurl.length != 0 && [[NSFileManager defaultManager] fileExistsAtPath:localFileurl]){
+        self.customFileSize = [self getFileSize];
+        NSLog(@"checkHasLocalPath 0: %@", localFileurl);
+        return localFileurl;
+    }
+    
+    NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
+    NSURL *tempUrl = [NSURL URLWithString:self.url];
+    NSString *fileName = tempUrl.lastPathComponent;
+    NSString *fileExtension = [fileName pathExtension];
+    NSString *newfileName = [NSString stringWithFormat:@"%@.%@", self.msgId,fileExtension];
+    NSString *path = [documentsDirectoryURL URLByAppendingPathComponent:newfileName].path;
+    if ([[NSFileManager defaultManager] fileExistsAtPath:path]){
+        NSLog(@"checkHasLocalPath 0: %@", path);
+        return path;
+    }
+    return nil;
+}
+
 @end

+ 4 - 31
AIIM/Controller/chat/chetCell/chatCellView.m

@@ -1518,38 +1518,11 @@ static const CGFloat kMediaCornerRadius = 4.0f;
             return;
         }
         
-        weakSelf(self);
+        [FilePreviewer.shared previewFileWithLocalPath:self.messageModel.localurl
+                                             remoteURL:getURL(self.messageModel.url)
+                                    fromViewController:self.parentViewController];
         [_messageModel downloadFileIfNeed:^(NSInteger persent) {
-            if(persent>=100){
-                dispatch_async(dispatch_get_main_queue(), ^{
-                    if(weakself.jinduLbl){
-                        weakself.jinduLbl.alpha = 0;
-                        weakself.loadingImg.alpha = 0;
-                    }
-                    [FilePreviewer.shared previewFileWithLocalPath:weakself.messageModel.localurl
-                                                         remoteURL:getURL(weakself.messageModel.url)
-                                                fromViewController:weakself.parentViewController];
-                });
-                
-                NSLog(@"下载完成:%@",self->_messageModel.localurl);
-            }
-            else{
-    //            NSLog(@"下载中:%ld",(long)persent);
-                dispatch_async(dispatch_get_main_queue(), ^{
-                    if(weakself.jinduLbl){
-                        if(weakself.loadingImg.alpha!=1||!weakself.loadingImg.image){
-                            NSString *gifPath = [[NSBundle mainBundle] pathForResource:@"load" ofType:@"gif"];
-                            NSData *gifData = [NSData dataWithContentsOfFile:gifPath];
-                            UIImage *placeholder = [UIImage sd_imageWithGIFData:gifData];
-                            weakself.loadingImg.image = placeholder;
-                            weakself.loadingImg.alpha = 1;
-                        }
-                        weakself.jinduLbl.alpha = 1;
-                        weakself.jinduLbl.text = [NSString stringWithFormat:@"%ld",(long)persent];
-                    }
-                });
-                
-            }
+            
         }];
     }
 }