瀏覽代碼

老师上传风采封面图

Steven 3 年之前
父節點
當前提交
b76e52acaf

二進制
KulexiuForTeacher/KulexiuForTeacher.xcworkspace/xcuserdata/wangzhi.xcuserdatad/UserInterfaceState.xcuserstate


+ 32 - 0
KulexiuForTeacher/KulexiuForTeacher.xcworkspace/xcuserdata/wangzhi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -1118,5 +1118,37 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "3833A111-E84F-4C8A-84A8-77778D8EBC8A"
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "KulexiuForTeacher/Module/Mine/CreateStyle/Controller/MyStyleViewController.m"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "79"
+            endingLineNumber = "79"
+            landmarkName = "-requestMyStyle"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "82BF61A7-2DBD-4167-AB25-40CF90BAF611"
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "KulexiuForTeacher/Module/Mine/CreateStyle/Controller/MyStyleViewController.m"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "251"
+            endingLineNumber = "251"
+            landmarkName = "-uploadUrlAndGetImagePath:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
    </Breakpoints>
 </Bucket>

+ 44 - 3
KulexiuForTeacher/KulexiuForTeacher/Module/Mine/CreateStyle/Controller/MyStyleViewController.m

@@ -14,6 +14,7 @@
 #import "KSMediaManager.h"
 #import "StyleVideoModel.h"
 #import "WMPlayer.h"
+#import "KSVideoHelper.h"
 
 @interface MyStyleViewController ()<UITableViewDelegate,UITableViewDataSource,WMPlayerDelegate>
 {
@@ -28,6 +29,8 @@
 
 @property (nonatomic, strong) NSMutableArray *videoArray;
 
+@property (nonatomic, strong) NSMutableArray *videoPageArray;
+
 @property (nonatomic, strong) NSString *content;
 
 @property (nonatomic, strong) UITableView *tableView;
@@ -132,9 +135,11 @@
         NSMutableDictionary *parm = [NSMutableDictionary dictionary];
         if (model.isChooseVideo) {
             [parm setValue:model.videoUrl forKey:@"videoUrl"];
+            [parm setValue:model.cover forKey:@"cover"];
         }
         else {
             [parm setValue:model.internalBaseClassIdentifier forKey:@"id"];
+            [parm setValue:model.cover forKey:@"cover"];
             [parm setValue:model.videoUrl forKey:@"videoUrl"];
         }
         [videoArray addObject:parm];
@@ -209,8 +214,10 @@
             MJWeakSelf;
             [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
                 NSLog(@"%@", videoUrl);
-                // 上传视频
-                [weakSelf uploadVideoWithUrl:videoUrl];
+                // 先选择首帧图
+                [weakSelf uploadUrlAndGetImagePath:videoUrl];
+//                // 上传视频
+//                [weakSelf uploadVideoWithUrl:videoUrl];
             }];
             [self.mediaManager pushImagePickerController];
         }
@@ -239,8 +246,34 @@
     }
 }
 
+- (void)uploadUrlAndGetImagePath:(NSString *)videoUrl {
+    [KSVideoHelper getLocalVideoPreViewUrlWithPath:videoUrl callback:^(UIImage * _Nullable firstImage) {
+        if (firstImage) {
+            // 上传图片
+            NSData *imgData = [UIImage compressImage:firstImage maxLength:5];
+            NSString *fileName = @"whiteboardImage";
+            [[KSUploadManager shareInstance] configBucketName:@"daya"];
+            [[KSUploadManager shareInstance] uploadImage:imgData fileName:fileName successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
+                NSString *imageUrl = [fileUrlArray lastObject];
+                [self uploadVideoWithUrl:videoUrl coverUrl:imageUrl];
+                
+            } faliure:^(NSError * _Nullable error, NSString * _Nullable descMessaeg) {
+                if ([NSString isEmptyString:descMessaeg]) {
+                    [self MBPShow:descMessaeg];
+                }
+            }];
+        }
+        else {
+            // 如果没有直接上传图片
+            [self uploadVideoWithUrl:videoUrl coverUrl:nil];
+        }
+        
+    }];
+}
+
+
 #pragma mark --- 上传视频文件
-- (void)uploadVideoWithUrl:(NSString *)videoUrl {
+- (void)uploadVideoWithUrl:(NSString *)videoUrl coverUrl:(NSString *)coverUrl {
     [self hudTipWillShow:YES];
     NSURL *fileUrl = [NSURL fileURLWithPath:videoUrl];
     NSData *fileData = [NSData dataWithContentsOfURL:fileUrl];
@@ -261,6 +294,7 @@
             StyleVideoModel *model = [[StyleVideoModel alloc] init];
             model.videoUrl = fileUrl;
             model.isChooseVideo = YES;
+            model.cover = coverUrl;
             [self.videoArray addObject:model];
             [self.tableView reloadData];
         } faliure:^(NSError * _Nullable error, NSString * _Nullable descMessaeg) {
@@ -380,6 +414,13 @@
     return _videoArray;
 }
 
+- (NSMutableArray *)videoPageArray {
+    if (!_videoPageArray) {
+        _videoPageArray = [NSMutableArray array];
+    }
+    return _videoPageArray;
+}
+
 - (void)hudTipWillShow:(BOOL)willShow{
     if (willShow) {
         [self resignFirstResponder];

+ 5 - 0
KulexiuForTeacher/KulexiuForTeacher/Module/Mine/CreateStyle/Model/KSVideoHelper.h

@@ -7,12 +7,17 @@
 
 #import <Foundation/Foundation.h>
 
+typedef void(^VideoFirstImgCallback)(UIImage * _Nullable firstImage);
+
 NS_ASSUME_NONNULL_BEGIN
 
 @interface KSVideoHelper : NSObject
 
 + (void)getVideoPreviewImageUrl:(NSString *)videoUrl forImageView:(UIImageView *)imageView placeholder:(UIImage *)placeHolder;
 
+
++ (void)getLocalVideoPreViewUrlWithPath:(NSString *)localPath callback:(VideoFirstImgCallback)callback;
+
 @end
 
 NS_ASSUME_NONNULL_END

+ 26 - 0
KulexiuForTeacher/KulexiuForTeacher/Module/Mine/CreateStyle/Model/KSVideoHelper.m

@@ -60,7 +60,33 @@
         });
           
     });
+}
 
++ (void)getLocalVideoPreViewUrlWithPath:(NSString *)localPath callback:(VideoFirstImgCallback)callback {
+    __block UIImage *videoImage;
+    dispatch_async(dispatch_get_global_queue(0, 0), ^{
+        AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:localPath] options:nil];
+        NSParameterAssert(asset);
+        AVAssetImageGenerator *assetImageGenerator =[[AVAssetImageGenerator alloc] initWithAsset:asset];
+        assetImageGenerator.appliesPreferredTrackTransform = YES;
+        assetImageGenerator.apertureMode =AVAssetImageGeneratorApertureModeEncodedPixels;
+        CGImageRef thumbnailImageRef = NULL;
+        NSError *thumbnailImageGenerationError = nil;
+        thumbnailImageRef = [assetImageGenerator copyCGImageAtTime:CMTimeMake(0, 60)actualTime:NULL error:&thumbnailImageGenerationError];
+        if(!thumbnailImageRef)
+        NSLog(@"thumbnailImageGenerationError %@",thumbnailImageGenerationError);
+        videoImage = thumbnailImageRef ? [[UIImage alloc]initWithCGImage:thumbnailImageRef]: nil;
+        
+        dispatch_async(dispatch_get_main_queue(), ^{
+            //主线程更新UI
+            if(videoImage){
+                callback(videoImage);
+                
+            }else{
+                callback(nil);
+            }
+        });
+    });
 }
 
 @end

+ 4 - 0
KulexiuForTeacher/KulexiuForTeacher/Module/Mine/CreateStyle/Model/StyleVideoModel.h

@@ -20,6 +20,10 @@
 @property (nonatomic, strong) NSString *createTime;
 @property (nonatomic, assign) BOOL isChooseVideo; // 是否本地选择的视频
 @property (nonatomic, strong) NSString *authStatus;
+@property (nonatomic, strong) NSString *cover;
+
+
+
 
 + (instancetype)modelObjectWithDictionary:(NSDictionary *)dict;
 - (instancetype)initWithDictionary:(NSDictionary *)dict;

+ 7 - 0
KulexiuForTeacher/KulexiuForTeacher/Module/Mine/CreateStyle/Model/StyleVideoModel.m

@@ -16,6 +16,7 @@ NSString *const kStyleVideoModelDescribe = @"describe";
 NSString *const kStyleVideoModelVideoUrl = @"videoUrl";
 NSString *const kStyleVideoModelCreateTime = @"createTime";
 NSString *const kStyleVideoModelAuthStatus = @"authStatus";
+NSString *const kStyleVideoModelCover = @"cover";
 
 @interface StyleVideoModel ()
 
@@ -33,6 +34,7 @@ NSString *const kStyleVideoModelAuthStatus = @"authStatus";
 @synthesize videoUrl = _videoUrl;
 @synthesize createTime = _createTime;
 @synthesize authStatus = _authStatus;
+@synthesize cover = _cover;
 
 + (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
 {
@@ -54,6 +56,7 @@ NSString *const kStyleVideoModelAuthStatus = @"authStatus";
             self.videoUrl = [self objectOrNilForKey:kStyleVideoModelVideoUrl fromDictionary:dict];
             self.createTime = [self objectOrNilForKey:kStyleVideoModelCreateTime fromDictionary:dict];
             self.authStatus = [self objectOrNilForKey:kStyleVideoModelAuthStatus fromDictionary:dict];
+            self.cover = [self objectOrNilForKey:kStyleVideoModelCover fromDictionary:dict];
     }
     
     return self;
@@ -71,6 +74,7 @@ NSString *const kStyleVideoModelAuthStatus = @"authStatus";
     [mutableDict setValue:self.videoUrl forKey:kStyleVideoModelVideoUrl];
     [mutableDict setValue:self.createTime forKey:kStyleVideoModelCreateTime];
     [mutableDict setValue:self.authStatus forKey:kStyleVideoModelAuthStatus];
+    [mutableDict setValue:self.cover forKey:kStyleVideoModelCover];
     
     return [NSDictionary dictionaryWithDictionary:mutableDict];
 }
@@ -106,6 +110,7 @@ NSString *const kStyleVideoModelAuthStatus = @"authStatus";
     self.videoUrl = [aDecoder decodeObjectForKey:kStyleVideoModelVideoUrl];
     self.createTime = [aDecoder decodeObjectForKey:kStyleVideoModelCreateTime];
     self.authStatus = [aDecoder decodeObjectForKey:kStyleVideoModelAuthStatus];
+    self.cover = [aDecoder decodeObjectForKey:kStyleVideoModelCover];
     return self;
 }
 
@@ -120,6 +125,7 @@ NSString *const kStyleVideoModelAuthStatus = @"authStatus";
     [aCoder encodeObject:_videoUrl forKey:kStyleVideoModelVideoUrl];
     [aCoder encodeObject:_createTime forKey:kStyleVideoModelCreateTime];
     [aCoder encodeObject:_authStatus forKey:kStyleVideoModelAuthStatus];
+    [aCoder encodeObject:_cover forKey:kStyleVideoModelCover];
 }
 
 - (id)copyWithZone:(NSZone *)zone
@@ -136,6 +142,7 @@ NSString *const kStyleVideoModelAuthStatus = @"authStatus";
         copy.videoUrl = [self.videoUrl copyWithZone:zone];
         copy.createTime = [self.createTime copyWithZone:zone];
         copy.authStatus = [self.createTime copyWithZone:zone];
+        copy.cover = [self.cover copyWithZone:zone];
     }
     
     return copy;

+ 7 - 1
KulexiuForTeacher/KulexiuForTeacher/Module/Mine/CreateStyle/View/MyStyleVideoView.m

@@ -42,7 +42,13 @@
 }
 
 - (void)configWithSource:(StyleVideoModel *)source {
-    [KSVideoHelper getVideoPreviewImageUrl:source.videoUrl forImageView:self.imageView placeholder:[UIImage imageNamed:@"video_placeholder"]];
+    if ([NSString isEmptyString:source.cover]) {
+        [KSVideoHelper getVideoPreviewImageUrl:source.videoUrl forImageView:self.imageView placeholder:[UIImage imageNamed:@"video_placeholder"]];
+    }
+    else {
+        [self.imageView sd_setImageWithURL:[NSURL URLWithString:[source.cover getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:@"video_placeholder"]];
+    }
+    
     if ([source.authStatus isEqualToString:@"DOING"]) {
         self.statusView.hidden = NO;
         self.statusLabel.text = @"审核中";