Parcourir la source

1.视频显示时长---差视频预览

huangxiaodong il y a 1 an
Parent
commit
5db3168a85

+ 62 - 0
创维盒子/双子星云手机/Class/Set/previewFile/view/imageCollectionViewCell.m

@@ -10,6 +10,7 @@
 @interface imageCollectionViewCell()
 @property (strong, nonatomic) UIImageView *imageView;
 @property (nonatomic, strong) UIButton *selectButton;
+@property (strong, nonatomic) UILabel *timeLabel;
 @end
 
 @implementation imageCollectionViewCell
@@ -58,6 +59,20 @@
     }];
     
     self.selectButton = but;
+    
+    _timeLabel = [[UILabel alloc] init];
+    _timeLabel.textColor = [UIColor whiteColor];
+    _timeLabel.font = [UIFont systemFontOfSize:14.0];
+    _timeLabel.textAlignment = NSTextAlignmentRight;
+    _timeLabel.hidden = YES;
+    [_imageView addSubview:_timeLabel];
+    
+    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.left.mas_equalTo(5);
+        make.right.mas_equalTo(-5);
+        make.height.mas_equalTo(20);
+        make.bottom.mas_equalTo(-5);
+    }];
 }
 
 - (void)setCurFileModel:(NASFilePicDataArrModel *)curFileModel
@@ -71,6 +86,52 @@
     UIImage *defaultImage = [UIImage imageNamed:@"uploadFile_image"];
     if([self.fileType isEqualToString:@"video"])
     {
+        _timeLabel.hidden = NO;
+        NSInteger curPlayTime = _curFileModel.duration;
+        NSInteger hourTime = 60*60;
+        NSInteger minTime = 60;
+        
+        NSString *playTimeStr = nil;
+        NSString *playHourTimeStr = nil;
+        NSString *playMinTimeStr = nil;
+        NSString *playSecondTimeStr = nil;
+        if(curPlayTime >= hourTime){
+            NSInteger hour = curPlayTime/hourTime;
+            playHourTimeStr = [[NSString alloc] initWithFormat:@"%ld",hour];
+            curPlayTime = curPlayTime % hourTime;
+        }
+        
+        if(curPlayTime >= minTime){
+            NSInteger min = curPlayTime/minTime;
+            if(min >=10){
+                playMinTimeStr = [[NSString alloc] initWithFormat:@"%ld",min];
+            }
+            else{
+                playMinTimeStr = [[NSString alloc] initWithFormat:@"0%ld",min];
+            }
+            curPlayTime = curPlayTime % min;
+        }
+        else{
+            playMinTimeStr = @"00";
+        }
+        
+        //秒
+        {
+            if(curPlayTime >=10){
+                playSecondTimeStr = [[NSString alloc] initWithFormat:@"%ld",curPlayTime];
+            }
+            else{
+                playSecondTimeStr = [[NSString alloc] initWithFormat:@"0%ld",curPlayTime];
+            }
+        }
+        
+        if(playHourTimeStr){
+            _timeLabel.text = [[NSString alloc] initWithFormat:@"%@:%@:%@",playHourTimeStr,playMinTimeStr,playSecondTimeStr];
+        }
+        else{
+            _timeLabel.text = [[NSString alloc] initWithFormat:@"%@:%@",playMinTimeStr,playSecondTimeStr];
+        }
+        
         defaultImage = [UIImage imageNamed:@"uploadFile_Video"];
     }
     else{
@@ -79,6 +140,7 @@
            ||[filePath rangeOfString:@".heic"].location != NSNotFound){
             fileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,filePath];
         }
+        _timeLabel.hidden = YES;
     }
 
     fileUrl = [fileUrl  stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];