浏览代码

合成loading优化

Steven 1 年之前
父节点
当前提交
92f729c45b

+ 21 - 17
KulexiuForTeacher/KulexiuForTeacher/Common/Base/KSAccompanyWebViewController.m

@@ -491,7 +491,7 @@
                  self.evaluatParm = nil;
                  [self stopRecordService];
                  [self postMessage:parm];
-                 [self sendEndMessage];
+//                 [self sendEndMessage];
                 [self stopMp3Player]; // 停止播放
             }
             else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"startRecording"]) { //  开始录制
@@ -910,24 +910,28 @@
             // 音视频合成
             else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"openAdjustRecording"]) {
                 KSMediaMergeView *mergeView = [[KSMediaMergeView alloc] init];
-                
-                if (self.AQManager && self.AQManager.audioUrl) {
-                    self.recordUrl = self.AQManager.audioUrl;
-                    [self.view addSubview:mergeView];
-                    [mergeView mas_makeConstraints:^(MASConstraintMaker *make) {
-                        make.left.right.top.bottom.mas_equalTo(self.view);
-                    }];
-                    NSDictionary *content = [parm ks_dictionaryValueForKey:@"content"];
-                    mergeView.recordId = [content ks_stringValueForKey:@"recordId"];
-                    mergeView.songName = [content ks_stringValueForKey:@"title"];
-                    mergeView.coverImage = [content ks_stringValueForKey:@"coverImg"];
-                    MJWeakSelf;
-                    [mergeView configWithVideoUrl:self.videoRecordManager.videoFileURL bgAudioUrl:self.bgAudioUrl remoteBgUrl:self.accompanyUrl  recordUrl:self.recordUrl offsetTime:self.offsetTime mergeCallback:^{
-                        [weakSelf musicPublishCallBack:content];
-                    }];
+                if (self.bgAudioUrl == nil) {
+                    [LOADING_MANAGER MBShowAUTOHidingInWindow:@"当前曲目无mp3伴奏"];
                 }
                 else {
-                    [LOADING_MANAGER MBShowAUTOHidingInWindow:@"麦克风被占用"];
+                    if (self.AQManager && self.AQManager.audioUrl) {
+                        self.recordUrl = self.AQManager.audioUrl;
+                        [self.view addSubview:mergeView];
+                        [mergeView mas_makeConstraints:^(MASConstraintMaker *make) {
+                            make.left.right.top.bottom.mas_equalTo(self.view);
+                        }];
+                        NSDictionary *content = [parm ks_dictionaryValueForKey:@"content"];
+                        mergeView.recordId = [content ks_stringValueForKey:@"recordId"];
+                        mergeView.songName = [content ks_stringValueForKey:@"title"];
+                        mergeView.coverImage = [content ks_stringValueForKey:@"coverImg"];
+                        MJWeakSelf;
+                        [mergeView configWithVideoUrl:self.videoRecordManager.videoFileURL bgAudioUrl:self.bgAudioUrl remoteBgUrl:self.accompanyUrl  recordUrl:self.recordUrl offsetTime:self.offsetTime mergeCallback:^{
+                            [weakSelf musicPublishCallBack:content];
+                        }];
+                    }
+                    else {
+                        [LOADING_MANAGER MBShowAUTOHidingInWindow:@"麦克风被占用"];
+                    }
                 }
             }
             else {

+ 16 - 2
KulexiuForTeacher/KulexiuForTeacher/Common/LoadingManager/KSHudLoagingManager.h

@@ -46,11 +46,25 @@ NS_ASSUME_NONNULL_BEGIN
 - (void)KSShowMsg:(NSString *)message inView:(UIView *)displayView promptCompletion:(void(^)(void))promptCompletion;
 // 提示后续操作
 - (void)KSShowMsg:(NSString *)message promptCompletion:(void(^)(void))promptCompletion;
+
+
+/// 加载进度loading
+/// - Parameters:
+///   - text: 文本
+///   - progress: 进度比例 0~1
+- (void)showProgressLoading:(NSString *)text progress:(CGFloat)progress;
+
 /// 加载进度loading
 /// - Parameters:
 ///   - text: 文本
-///   - progress: 进度比例 0~100
-- (void)showProgressLoading:(NSString *)text progress:(NSInteger)progress;
+///   - progress: 进度比例 0~1
+- (void)showProgressNoAnimationLoading:(NSString *)text progress:(CGFloat)progress;
+/// 加载进度loading 完成后回调
+/// - Parameters:
+///   - text: 文本
+///   - progress: 进度比例 0~1
+///   - promptCompletion: 回调
+- (void)showProgressLoading:(NSString *)text progress:(CGFloat)progress promptCompletion:(void(^)(void))promptCompletion;
 
 /// 移除进度loading
 - (void)removeProgressLoading;

+ 60 - 20
KulexiuForTeacher/KulexiuForTeacher/Common/LoadingManager/KSHudLoagingManager.m

@@ -12,6 +12,7 @@
 
 @interface KSHudLoagingManager ()
 
+
 @end
 
 @implementation KSHudLoagingManager
@@ -36,6 +37,8 @@
 - (void)removeCustomLoading {
     [self.loadingView hideLoadingView];
 }
+
+
 - (void)showHUD {
     dispatch_main_async_safe(^{
         [self removeLoadingView];
@@ -52,7 +55,7 @@
 }
 
 - (void)removeHUD {
-    dispatch_main_async_safe(^{
+    dispatch_delay_block(DISPATCH_TIME_NOW, (int64_t)(0.5f * NSEC_PER_SEC), ^{
         [self removeLoadingView];
     });
 }
@@ -102,31 +105,44 @@
     [self showHud:str inView:[NSObject getKeyWindow] autoHide:YES];
 }
 
+
+- (MBProgressHUD *)MBPShowLoadingHubWithText:(NSString *)text {
+    [self removeLoadingView];
+    self.HUD = [MBProgressHUD showHUDAddedTo:[NSObject getKeyWindow] animated:YES];
+    self.HUD.mode = MBProgressHUDModeDeterminateHorizontalBar;
+    self.HUD.label.text = text;
+    self.HUD.contentColor = [UIColor whiteColor];
+    self.HUD.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
+    self.HUD.bezelView.backgroundColor = HexRGBAlpha(0x000000, 0.8f);
+    self.HUD.removeFromSuperViewOnHide = YES;
+    self.HUD.progress = 0;
+    return self.HUD;
+}
+
 - (void)KSShowMsg:(NSString *)message promptCompletion:(void (^)(void))promptCompletion {
     [self KSShowMsg:message inView:[NSObject getKeyWindow] promptCompletion:promptCompletion];
     
 }
 
 - (void)KSShowMsg:(NSString *)message inView:(UIView *)displayView promptCompletion:(void (^)(void))promptCompletion {
-    dispatch_main_async_safe(^{
-        [self removeLoadingView];
-        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:displayView animated:YES];
-        hud.removeFromSuperViewOnHide = YES;
-        hud.mode = MBProgressHUDModeText;
-        hud.label.text = message;
-        hud.label.numberOfLines = 0;
-        hud.label.textColor = [UIColor whiteColor];
-        hud.minSize = CGSizeMake(132.0f, 40.0f);
-        hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
-        hud.bezelView.backgroundColor = HexRGBAlpha(0x000000, 0.8);
-        [hud hideAnimated:YES afterDelay:PROMPT_TIME];
-        
-        dispatch_delay_block(DISPATCH_TIME_NOW, (int64_t)(PROMPT_TIME * NSEC_PER_SEC), ^{
-            promptCompletion();
-        });
+    [self removeLoadingView];
+    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:displayView animated:YES];
+    hud.removeFromSuperViewOnHide = YES;
+    hud.mode = MBProgressHUDModeText;
+    hud.label.text = message;
+    hud.label.numberOfLines = 0;
+    hud.label.textColor = [UIColor whiteColor];
+    hud.minSize = CGSizeMake(132.0f, 40.0f);
+    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
+    hud.bezelView.backgroundColor = HexRGBAlpha(0x000000, 0.8);
+    [hud hideAnimated:YES afterDelay:PROMPT_TIME];
+    
+    dispatch_delay_block(DISPATCH_TIME_NOW, (int64_t)(PROMPT_TIME * NSEC_PER_SEC), ^{
+        promptCompletion();
     });
 }
 
+
 - (KSCustomLoadingView *)loadingView {
     if (!_loadingView) {
         _loadingView = [KSCustomLoadingView shareInstance];
@@ -144,13 +160,37 @@
 /// 加载进度loading
 /// - Parameters:
 ///   - text: 文本
-///   - progress: 进度比例 0~100
-- (void)showProgressLoading:(NSString *)text progress:(NSInteger)progress {
+///   - progress: 进度比例 0~1
+- (void)showProgressLoading:(NSString *)text progress:(CGFloat)progress {
     dispatch_main_async_safe(^{
         [self.progressLoading configProgressWithText:text progress:progress];
         [self.progressLoading showLoadingView];
     });
 }
+/// 加载进度loading
+/// - Parameters:
+///   - text: 文本
+///   - progress: 进度比例 0~1
+- (void)showProgressNoAnimationLoading:(NSString *)text progress:(CGFloat)progress {
+    dispatch_main_async_safe(^{
+        [self.progressLoading configProgressNoAnimationWithText:text progress:progress];
+        [self.progressLoading showLoadingView];
+    });
+}
+/// 加载进度loading 完成后回调
+/// - Parameters:
+///   - text: 文本
+///   - progress: 进度比例 0~1
+///   - promptCompletion: 回调
+- (void)showProgressLoading:(NSString *)text progress:(CGFloat)progress promptCompletion:(void(^)(void))promptCompletion {
+    dispatch_main_async_safe(^{
+        [self.progressLoading configProgressWithText:text progress:progress promptCompletion:^{
+            promptCompletion();
+        }];
+        [self.progressLoading showLoadingView];
+    });
+    
+}
 
 /// 移除进度loading
 - (void)removeProgressLoading {
@@ -166,7 +206,7 @@
 
 // 进度loading后续操作
 - (void)KSShowProgressMsg:(NSString *)message promptCompletion:(void(^)(void))promptCompletion {
-    [self.progressLoading configProgressWithText:message progress:100];
+    [self.progressLoading configProgressWithText:message progress:1];
     
     dispatch_delay_block(DISPATCH_TIME_NOW, (int64_t)(PROMPT_TIME * NSEC_PER_SEC), ^{
         [self removeProgressLoadingNoDelay];

+ 5 - 1
KulexiuForTeacher/KulexiuForTeacher/Common/LoadingManager/KSProgressLoadingView.h

@@ -14,7 +14,11 @@ NS_ASSUME_NONNULL_BEGIN
 
 + (instancetype)shareInstance;
 
-- (void)configProgressWithText:(NSString *)tipsMessage progress:(NSInteger)progress;
+- (void)configProgressWithText:(NSString *)tipsMessage progress:(CGFloat)progress;
+
+- (void)configProgressNoAnimationWithText:(NSString *)tipsMessage progress:(CGFloat)progress;
+
+- (void)configProgressWithText:(NSString *)tipsMessage progress:(CGFloat)progress promptCompletion:(void(^)(void))promptCompletion;
 
 - (void)showLoadingView;
 

+ 29 - 7
KulexiuForTeacher/KulexiuForTeacher/Common/LoadingManager/KSProgressLoadingView.m

@@ -21,20 +21,42 @@
 @end
 
 @implementation KSProgressLoadingView
-
+- (void)awakeFromNib {
+    [super awakeFromNib];
+    self.progress = 0;
+    self.leadingSpace.constant = 0.0f;
+}
 + (instancetype)shareInstance {
     KSProgressLoadingView *view = [[[NSBundle mainBundle] loadNibNamed:@"KSProgressLoadingView" owner:nil options:nil] firstObject];
     return view;
 }
 
-- (void)configProgressWithText:(NSString *)tipsMessage progress:(NSInteger)progress {
+- (void)configProgressWithText:(NSString *)tipsMessage progress:(CGFloat)progress {
     self.progressTipsLabel.text = tipsMessage;
-    NSInteger space = progress * 1.0 / 100 * 280;
-    self.progress = space;
-    [UIView animateWithDuration:0.3f animations:^{
+    NSInteger space = progress * 280;
+    [UIView animateWithDuration:0.5f animations:^{
+        self.progress = space;
         self.leadingSpace.constant = space;
     }];
-    
+}
+
+- (void)configProgressNoAnimationWithText:(NSString *)tipsMessage progress:(CGFloat)progress {
+    self.progressTipsLabel.text = tipsMessage;
+    NSInteger space = progress * 280;
+    self.progress = space;
+    self.leadingSpace.constant = space;
+}
+
+- (void)configProgressWithText:(NSString *)tipsMessage progress:(CGFloat)progress promptCompletion:(void(^)(void))promptCompletion {
+    self.progressTipsLabel.text = tipsMessage;
+    NSInteger space = progress * 280;
+    self.progress = space;
+    self.leadingSpace.constant = space;
+    [UIView animateWithDuration:0.5 delay:1 options:UIViewAnimationOptionCurveEaseInOut animations:^{
+        
+    } completion:^(BOOL finished) {
+        promptCompletion();
+    }];
 }
 
 - (void)showLoadingView {
@@ -52,7 +74,7 @@
 - (void)setProgress:(NSInteger)progress {
     _progress = progress;
     CGFloat width = progress;
-    [self.progressFillImage setImage:[self createGradientImageWithColor:@[HexRGB(0x44F1D0),HexRGB(0x2DC7AA)] rect:CGRectMake(0, 0, width, 8) start:CGPointMake(0.41, 0) end:CGPointMake(0.41, 1)]];
+    [self.progressFillImage setImage:[self createGradientImageWithColor:@[HexRGB(0x3CD6F9),HexRGB(0x1CACF1)] rect:CGRectMake(0, 0, width, 8) start:CGPointMake(0.41, 0) end:CGPointMake(0.41, 1)]];
     self.imageWidth.constant = width;
 }
 

+ 108 - 159
KulexiuForTeacher/KulexiuForTeacher/Common/MediaMerge/AudioMerge/KSMediaMergeView.m

@@ -13,7 +13,6 @@
 #import "KSPlayerSliderView.h"
 #import "kSNewPlayer.h"
 #import "KSVideoPlayerView.h"
-#import "TZImageManager.h"
 #import "KSUploadManager.h"
 #import "KSAudioPlayAnimationView.h"
 #import "KSNewAlertView.h"
@@ -59,10 +58,6 @@
 
 @property (nonatomic, strong) UIButton *showButton;
 
-@property (nonatomic, strong) PHAsset *videoAsset;
-
-@property (nonatomic, strong) NSString *presentName;
-
 @property (nonatomic, strong) KSAudioPlayAnimationView *playAnimationView;
 
 @property (nonatomic, strong) NSTimer *timer;
@@ -107,8 +102,6 @@
 
 @property (nonatomic, strong) NSString *videoCoverUrl; // 视频封面
 
-@property (nonatomic, strong) dispatch_group_t uploadGroup;
-
 @end
 
 @implementation KSMediaMergeView
@@ -118,10 +111,16 @@
     if (self) {
         self.hasModify = NO;
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appEnterBackground) name:@"appEnterBackground" object:nil];
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(otherLogin) name:@"otherLogin" object:nil];
     }
     return self;
 }
 
+- (void)otherLogin {
+    [self stopPlay];
+}
+
+
 - (void)appEnterBackground {
     [self stopPlay];
 }
@@ -323,6 +322,8 @@
             make.centerX.mas_equalTo(self.playerView.mas_centerX);
             make.top.mas_equalTo(self.animationView.mas_top).offset(86);
         }];
+        [self.animationView configWithImageWithUrl:self.coverImage];
+
     }
     
     [self addSubview:self.playControlView];
@@ -653,6 +654,12 @@
             [baseCtrl.navigationController presentViewController:ctrl animated:YES completion:nil];
         }
             break;
+        case PUBLISH_ACTION_CANCLE:
+        {
+            self.settingImage = nil;
+            self.videoCoverImage = nil;
+        }
+            break;
         default:
             break;
     }
@@ -665,52 +672,52 @@
 
 - (void)updateWithCoverImage {
     
-    if (self.settingImage) {
-        [self uploadMusicCover];
-    }
-    if (self.videoCoverImage) {
-        [self uploadVideoCover];
-    }
-    
-    dispatch_group_notify(self.uploadGroup, dispatch_get_main_queue(), ^{
-        [self publishMusic];
-    });
+    [self uploadMusicCover];
 }
 
 - (void)uploadMusicCover {
-    dispatch_group_enter(self.uploadGroup);
 
-    NSData *imgData = [UIImage turnsImaegDataByImage:self.settingImage];
-    NSString *fileName = @"musicCoverImg";
-    [[KSUploadManager shareInstance] configBucketName:@"klx"];
-    [[KSUploadManager shareInstance] uploadImage:imgData fileName:fileName successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
-        NSString *avatarUrl = [fileUrlArray lastObject];
-        self.coverImage = avatarUrl;
-        dispatch_group_leave(self.uploadGroup);
-    } faliure:^(NSError * _Nullable error, NSString *descMessaeg) {
-        if ([NSString isEmptyString:descMessaeg]) {
-            [LOADING_MANAGER MBShowAUTOHidingInWindow:descMessaeg];
-        }
-        dispatch_group_leave(self.uploadGroup);
-    }];
+    if (self.settingImage) {
+        NSData *imgData = [UIImage turnsImaegDataByImage:self.settingImage];
+        NSString *fileName = @"musicCoverImg";
+        [[KSUploadManager shareInstance] configBucketName:@"klx"];
+        [[KSUploadManager shareInstance] uploadImage:imgData fileName:fileName successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
+            NSString *avatarUrl = [fileUrlArray lastObject];
+            self.coverImage = avatarUrl;
+            [self uploadVideoCover];
+        } faliure:^(NSError * _Nullable error, NSString *descMessaeg) {
+            if (![NSString isEmptyString:descMessaeg]) {
+                [LOADING_MANAGER MBShowAUTOHidingInWindow:descMessaeg];
+            }
+            [self uploadVideoCover];
+        }];
+    }
+    else {
+        [self uploadVideoCover];
+    }
 }
 
 - (void)uploadVideoCover {
-    dispatch_group_enter(self.uploadGroup);
-    NSData *imgData = [UIImage turnsImaegDataByImage:self.videoCoverImage];
-    NSString *fileName = @"musicCoverImg";
-    [[KSUploadManager shareInstance] configBucketName:@"klx"];
-    [[KSUploadManager shareInstance] uploadImage:imgData fileName:fileName successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
-        NSString *avatarUrl = [fileUrlArray lastObject];
-        self.videoCoverUrl = avatarUrl;
-        dispatch_group_leave(self.uploadGroup);
-    } faliure:^(NSError * _Nullable error, NSString *descMessaeg) {
-        if ([NSString isEmptyString:descMessaeg]) {
-            [LOADING_MANAGER MBShowAUTOHidingInWindow:descMessaeg];
-        }
-        dispatch_group_leave(self.uploadGroup);
-
-    }];
+    if (self.videoCoverImage) {
+        NSData *imgData = [UIImage turnsImaegDataByImage:self.videoCoverImage];
+        NSString *fileName = @"musicCoverImg";
+        [[KSUploadManager shareInstance] configBucketName:@"klx"];
+        [[KSUploadManager shareInstance] uploadImage:imgData fileName:fileName successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
+            NSString *avatarUrl = [fileUrlArray lastObject];
+            self.videoCoverUrl = avatarUrl;
+            [self publishMusic];
+
+        } faliure:^(NSError * _Nullable error, NSString *descMessaeg) {
+            if (![NSString isEmptyString:descMessaeg]) {
+                [LOADING_MANAGER MBShowAUTOHidingInWindow:descMessaeg];
+            }
+            [self publishMusic];
+        }];
+    }
+    else {
+        [self publishMusic];
+    }
+    
 }
 
 - (void)refreshViewCoverImg:(NSMutableArray *)imageArray {
@@ -721,41 +728,50 @@
 
 
 - (void)publishMusic {
+    CGFloat progress = 1.0/3;
+    CGFloat rate = 1.0/3;
     if (self.isVideoPlay) {
-        [LOADING_MANAGER showProgressLoading:@"视频合成中" progress:33];
+        [LOADING_MANAGER showProgressLoading:@"视频合成中..." progress:0];
+        
         [KSMediaEditor mixVideoWithRecordAudio:self.recordUrl recordVolume:self.recordPlayer.volume bgAudio:self.bgAudioUrl bgAudioVolume:self.bgPlayer.volume offsetTime:self.offsetTime videoUrlStr:self.videoUrl completion:^(NSString * _Nonnull outPath, BOOL isSuccess, NSString * _Nonnull desc) {
+            [LOADING_MANAGER showProgressLoading:@"视频合成中..." progress:progress];
             // 保存文件到指定文件夹
             if (isSuccess) {
                 self.filePath = outPath;
                 MJWeakSelf;
-                [self sendVideoActionWithUrl:outPath isFormal:YES success:^(NSString * _Nonnull uploadVideoUrl) {
-                    [weakSelf saveMusic:YES isFormal:YES fileUrl:uploadVideoUrl progress:66];
+                [self sendVideoActionWithUrl:outPath isFormal:YES startProgress:progress rate:rate success:^(NSString * _Nonnull uploadVideoUrl) {
+                    [weakSelf saveMusic:YES isFormal:YES fileUrl:uploadVideoUrl progress:progress*2];
 
                 } failure:^(NSString * _Nonnull desc) {
-                    
+                    [LOADING_MANAGER MBShowAUTOHidingInWindow:@"上传失败"];
                 }];
             }
             else {
                 [LOADING_MANAGER removeProgressLoading];
+                [LOADING_MANAGER MBShowAUTOHidingInWindow:@"视频合成失败"];
             }
         }];
     }
     else {
-        [LOADING_MANAGER showProgressLoading:@"音频合成中..." progress:33];
+        [LOADING_MANAGER showProgressLoading:@"音频合成中..." progress:0];
         NSInteger realOffsetTime = self.offsetTime;
         [KSMediaEditor mixRecordAudio:self.recordUrl recordVolume:self.recordPlayer.volume bgAudio:self.bgAudioUrl bgAudioVolume:self.bgPlayer.volume offsetTime:realOffsetTime completion:^(NSString * _Nonnull outPath, BOOL isSuccess, NSString * _Nonnull desc) {
             // 保存文件到指定文件夹
+            [LOADING_MANAGER showProgressLoading:@"音频合成中..." progress:progress];
+
             if (isSuccess) {
                 self.filePath = outPath;
                 MJWeakSelf;
-                [self sendAudioWithPath:outPath isFormal:YES success:^(NSString *audioUrl) {
-                    [weakSelf saveMusic:NO isFormal:YES fileUrl:audioUrl progress:66];
+                [self sendAudioWithPath:outPath isFormal:YES startProgress:progress rate:rate success:^(NSString *audioUrl) {
+                    [weakSelf saveMusic:NO isFormal:YES fileUrl:audioUrl progress:progress*2];
+
                 } failure:^(NSString *desc) {
-                    [LOADING_MANAGER MBShowAUTOHidingInWindow:@"文件上传失败"];
+                    [LOADING_MANAGER MBShowAUTOHidingInWindow:@"上传失败"];
                 }];
             }
             else {
                 [LOADING_MANAGER removeProgressLoading];
+                [LOADING_MANAGER MBShowAUTOHidingInWindow:@"音频合成失败"];
             }
         }];
     }
@@ -767,20 +783,24 @@
     if (self.isVideoPlay) {
         if (self.remoteVideoUrl) {
             // 保存草稿
-            [self saveMusic:YES isFormal:NO fileUrl:self.remoteVideoUrl needBack:needBack progress:33];
+            [LOADING_MANAGER showProgressLoading:@"正在保存草稿" progress:0 promptCompletion:^{
+                [self saveMusic:YES isFormal:NO fileUrl:self.remoteVideoUrl needBack:needBack progress:0.5];
+            }];
         }
         else {
             // 合成
-            [LOADING_MANAGER showProgressLoading:@"加载中..." progress:33];
+            [LOADING_MANAGER showProgressLoading:@"正在上传草稿" progress:0];
             MJWeakSelf;
             [KSMediaEditor mixRecordVideoWithAudio:self.recordUrl recordVolume:100 videoUrlStr:self.videoUrl completion:^(NSString * _Nonnull outPath, BOOL isSuccess, NSString * _Nonnull desc) {
                 if (isSuccess) {
-                    [self sendVideoActionWithUrl:outPath isFormal:NO success:^(NSString * _Nonnull uploadVideoUrl) {
+                    [self sendVideoActionWithUrl:outPath isFormal:NO startProgress:0 rate:0.5 success:^(NSString * _Nonnull uploadVideoUrl) {
                         // 保存草稿
-                        [weakSelf saveMusic:YES isFormal:NO fileUrl:uploadVideoUrl needBack:needBack progress:66];
+                        [weakSelf saveMusic:YES isFormal:NO fileUrl:uploadVideoUrl needBack:needBack progress:0.5];
+                        
                     } failure:^(NSString * _Nonnull desc) {
                         [LOADING_MANAGER MBShowAUTOHidingInWindow:@"上传失败"];
                     }];
+
                 }
                 else {
                     [LOADING_MANAGER MBShowAUTOHidingInWindow:@"上传失败"];
@@ -790,15 +810,19 @@
     }
     else {
         if (self.remoteRecrodUrl) {
-            [self saveMusic:NO isFormal:NO fileUrl:self.remoteRecrodUrl needBack:needBack progress:33];
+            [LOADING_MANAGER showProgressLoading:@"正在保存草稿" progress:0 promptCompletion:^{
+                [self saveMusic:NO isFormal:NO fileUrl:self.remoteRecrodUrl needBack:needBack progress:0.5];
+            }];
         }
         else {
             MJWeakSelf;
-            [self sendAudioWithURLPath:self.recordUrl isFormal:NO success:^(NSString *audioUrl) {
-                
-                [weakSelf saveMusic:NO isFormal:NO fileUrl:audioUrl needBack:needBack progress:33];
+            [LOADING_MANAGER showProgressLoading:@"正在上传草稿" progress:0];
+            [self sendAudioWithURLPath:self.recordUrl isFormal:NO startProgress:0 rate:0.5 success:^(NSString *audioUrl) {
+                // 保存草稿
+                [weakSelf saveMusic:NO isFormal:NO fileUrl:audioUrl needBack:needBack progress:0.5];
+
             } failure:^(NSString *desc) {
-                [LOADING_MANAGER MBShowAUTOHidingInWindow:@"文件上传失败"];
+                [LOADING_MANAGER MBShowAUTOHidingInWindow:@"上传失败"];
             }];
         }
     }
@@ -923,52 +947,18 @@
 }
 
 
-- (void)saveVideoURLToAsset:(NSURL *)videoUrl isFormal:(BOOL)isFormal callback:(void(^)(NSString *videoUrl))callback {
-    
-    [[TZImageManager manager] saveVideoWithUrl:videoUrl completion:^(PHAsset *asset, NSError *error) {
-        if (!error) {
-            self.videoAsset = asset;
-            dispatch_main_async_safe(^{
-                
-                if (callback) {
-                    [self uploadRecordVideoisFormal:isFormal Success:^(NSString *uploadVideoUrl) {
-                        callback(uploadVideoUrl);
-                        
-                    } failure:^(NSString *desc) {
-                        [LOADING_MANAGER MBShowAUTOHidingInWindow:@"上传视频失败"];
-                    }];
-                }
-                
-            });
-        }
-        else {
-            dispatch_main_async_safe(^{
-                [LOADING_MANAGER MBShowAUTOHidingInWindow:@"保存视频错误"];
-            });
-        }
-    }];
-}
-
-- (void)saveVideoToAsset:(NSString *)saveVideoUrl isFormal:(BOOL)isFormal callback:(void(^)(NSString *videoUrl))callback {
-    NSURL *fileUrl = [NSURL fileURLWithPath:saveVideoUrl];
-    [self saveVideoURLToAsset:fileUrl isFormal:isFormal callback:^(NSString *videoUrl) {
-        callback(videoUrl);
-    }];
-}
-
-- (void)saveMusic:(BOOL)isVideo isFormal:(BOOL)isFormal fileUrl:(NSString *)fileUrl progress:(NSInteger)progress  {
+- (void)saveMusic:(BOOL)isVideo isFormal:(BOOL)isFormal fileUrl:(NSString *)fileUrl progress:(CGFloat)progress  {
     
     [self saveMusic:isVideo isFormal:isFormal fileUrl:fileUrl needBack:NO progress:progress];
 }
 
-- (void)saveMusic:(BOOL)isVideo isFormal:(BOOL)isFormal fileUrl:(NSString *)fileUrl needBack:(BOOL)needBack progress:(NSInteger)progress {
+- (void)saveMusic:(BOOL)isVideo isFormal:(BOOL)isFormal fileUrl:(NSString *)fileUrl needBack:(BOOL)needBack progress:(CGFloat)progress {
     NSString *type = isFormal ? @"FORMAL" : @"DRAFT";
     NSMutableDictionary *parm = [NSMutableDictionary dictionary];
     [parm setValue:@(self.offsetTime) forKey:@"offset"];
     [parm setValue:@(self.originalVolume) forKey:@"originalVolume"];
     [parm setValue:@(self.accompanyVolume) forKey:@"accompanyVolume"];
     self.jsonConfig = [parm mj_JSONString];
-    [LOADING_MANAGER showProgressLoading:@"加载中..." progress:progress];
     [KSNetworkingManager saveMusicMessage:KS_POST jsonConfig:self.jsonConfig img:self.coverImage videoUrl:fileUrl accompanyUrl:self.remoteBgAudioUrl desc:self.desc type:type musicPracticeRecordId:self.recordId videoImg:self.videoCoverUrl success:^(NSDictionary * _Nonnull dic) {
         if ([dic ks_integerValueForKey:@"code"] == 200) {
             if (isFormal) {
@@ -994,46 +984,18 @@
     }];
 }
 
-// 上传视频
-- (void)uploadRecordVideoisFormal:(BOOL)isFormal Success:(void(^)(NSString *uploadVideoUrl))success failure:(void(^)(NSString *desc))faliure {
-    if (self.videoAsset) {
-        if (self.videoAsset) {
-
-            [[TZImageManager manager] getVideoOutputPathWithAsset:self.videoAsset presetName:self.presentName success:^(NSString *outputPath) {
-
-                NSLog(@"视频导出到本地完成,沙盒路径为:%@",outputPath);
-                NSData *outputData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:outputPath]]; //压缩后的视频
-                NSLog(@"导出后的视频:%@",[NSString stringWithFormat:@"%.2fM",(CGFloat)outputData.length/(1024*1024)]);
-                // 上传
-                dispatch_main_async_safe(^{
-                    [self sendVideoActionWithUrl:outputPath isFormal:isFormal success:success failure:faliure];
-                });
-                
-            } failure:^(NSString *errorMessage, NSError *error) {
-                dispatch_main_async_safe(^{
-                    faliure(@"视频导出失败");
-                });
-                NSLog(@"视频导出失败:%@,error:%@",errorMessage, error);
-                
-            }];
-        }
-        else {
-            faliure(@"未找到视频资源");
-        }
-    }
-    else {
-        faliure(@"未找到视频资源");
-    }
-}
-
-- (void)sendVideoActionWithUrlPath:(NSURL *)fileUrl isFormal:(BOOL)isFormal success:(void (^)(NSString * _Nonnull uploadVideoUrl))success failure:(void (^)(NSString * _Nonnull desc))faliure {
+- (void)sendVideoActionWithUrlPath:(NSURL *)fileUrl isFormal:(BOOL)isFormal beginProgress:(CGFloat)beginProgress rate:(CGFloat)rate success:(void (^)(NSString * _Nonnull uploadVideoUrl))success failure:(void (^)(NSString * _Nonnull desc))faliure {
     NSString *tips = isFormal ? @"正在上传作品" : @"正在上传草稿";
-    [LOADING_MANAGER showProgressLoading:tips progress:66];
+    [LOADING_MANAGER showProgressLoading:tips progress:beginProgress];
     NSData *fileData = [NSData dataWithContentsOfURL:fileUrl];
     NSString *suffix = [NSString stringWithFormat:@".%@",[fileUrl pathExtension]];
     [[KSUploadManager shareInstance] configBucketName:@"klx"];
     [[KSUploadManager shareInstance] videoUpload:fileData fileName:@"video" fileSuffix:suffix progress:^(int64_t bytesWritten, int64_t totalBytes) {
-
+        // 显示进度
+        float progress = (bytesWritten*1.0 / totalBytes) * rate + beginProgress;
+        dispatch_main_async_safe(^{
+            [LOADING_MANAGER showProgressNoAnimationLoading:tips progress:progress];
+        });
     } successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
         dispatch_main_async_safe(^{
             NSString *fileUrl = [fileUrlArray lastObject];
@@ -1050,19 +1012,23 @@
     }];
 }
 
-- (void)sendVideoActionWithUrl:(NSString *)fileUrl isFormal:(BOOL)isFormal success:(void (^)(NSString * _Nonnull uploadVideoUrl))success failure:(void (^)(NSString * _Nonnull desc))faliure {
-    [self sendAudioWithURLPath:[NSURL fileURLWithPath:fileUrl] isFormal:isFormal success:success failure:faliure];
+- (void)sendVideoActionWithUrl:(NSString *)fileUrl isFormal:(BOOL)isFormal startProgress:(CGFloat)beginProgress rate:(CGFloat)rate success:(void (^)(NSString * _Nonnull uploadVideoUrl))success failure:(void (^)(NSString * _Nonnull desc))faliure {
+    [self sendVideoActionWithUrlPath:[NSURL fileURLWithPath:fileUrl] isFormal:isFormal beginProgress:beginProgress rate:rate success:success failure:faliure];
 }
 
-- (void)sendAudioWithURLPath:(NSURL *)fileUrl isFormal:(BOOL)isFormal success:(void(^)(NSString *audioUrl))success failure:(void(^)(NSString *desc))faliure {
+- (void)sendAudioWithURLPath:(NSURL *)fileUrl isFormal:(BOOL)isFormal startProgress:(CGFloat)beginProgress rate:(CGFloat)rate success:(void(^)(NSString *audioUrl))success failure:(void(^)(NSString *desc))faliure {
     NSString *tips = isFormal ? @"正在上传作品" : @"正在上传草稿";
 
-    [LOADING_MANAGER showProgressLoading:tips progress:66];
+    [LOADING_MANAGER showProgressLoading:tips progress:beginProgress];
     NSData *fileData = [NSData dataWithContentsOfURL:fileUrl];
     NSString *suffix = [NSString stringWithFormat:@".%@",[fileUrl pathExtension]];
     [[KSUploadManager shareInstance] configBucketName:@"klx"];
     [UPLOAD_MANAGER uploadFile:fileData fileName:@"evaluateAudio" fileSuffix:suffix progress:^(int64_t bytesWritten, int64_t totalBytes) {
-
+        // 显示进度
+        float progress = (bytesWritten*1.0 / totalBytes) * rate + beginProgress;
+        dispatch_main_async_safe(^{
+            [LOADING_MANAGER showProgressNoAnimationLoading:tips progress:progress];
+        });
     } successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
         NSString *fileUrl = [fileUrlArray lastObject];
         success(fileUrl);
@@ -1073,21 +1039,9 @@
     
 }
 
-- (void)sendAudioWithPath:(NSString *)filePath isFormal:(BOOL)isFormal success:(void(^)(NSString *audioUrl))success failure:(void(^)(NSString *desc))faliure {
+- (void)sendAudioWithPath:(NSString *)filePath isFormal:(BOOL)isFormal startProgress:(CGFloat)beginProgress rate:(CGFloat)rate success:(void(^)(NSString *audioUrl))success failure:(void(^)(NSString *desc))faliure {
     NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
-    [self sendAudioWithURLPath:fileUrl isFormal:isFormal success:success failure:faliure];
-}
-
-- (NSString *)presentName {
-    NSString *presentName = AVAssetExportPresetMediumQuality;
-    if ([[NSString deviceVersion] containsString:@"iPhone 12"]) {
-        
-        presentName =  AVAssetExportPreset640x480;
-    }
-    else {
-        presentName = AVAssetExportPresetMediumQuality;
-    }
-    return presentName;
+    [self sendAudioWithURLPath:fileUrl isFormal:isFormal startProgress:beginProgress rate:rate  success:success failure:faliure];
 }
 
 - (void)removeVideoWithPath:(NSString *)videoUrl {
@@ -1149,12 +1103,7 @@
     }
     return _requestGroup;
 }
-- (dispatch_group_t)uploadGroup {
-    if (!_uploadGroup) {
-        _uploadGroup = dispatch_group_create();
-    }
-    return _uploadGroup;
-}
+
 - (KSNewAlertView *)alertView {
     if (!_alertView) {
         _alertView = [KSNewAlertView shareInstance];

+ 37 - 15
KulexiuForTeacher/KulexiuForTeacher/Module/Mine/Works/Controller/KSVideoCropViewController.m

@@ -32,6 +32,9 @@
 @property (nonatomic, strong) KSVideoImageSlider *imageSlider;
 
 @property (nonatomic, assign) BOOL needChangeOrigin;
+
+@property (nonatomic, strong) NSString *remoteUrl;
+
 @end
 
 @implementation KSVideoCropViewController
@@ -55,6 +58,32 @@
     [super viewDidLoad];
     // Do any additional setup after loading the view.
     [self configUI];
+    
+}
+
+- (void)viewDidAppear:(BOOL)animated {
+    [super viewDidAppear:animated];
+    [self evaluateSource];
+}
+
+- (void)evaluateSource {
+    if (self.videoUrl) { //
+        [LOADING_MANAGER showCustomLoading:@"资源加载中..."];
+        [self configImageWallWithPath:self.videoUrl];
+    }
+    else if (self.remoteUrl) {
+        [self downloadUrl];
+    }
+}
+
+- (void)downloadUrl {
+    [LOADING_MANAGER showCustomLoading:@"视频下载中..."];
+    [KSNetworkingManager downloadFileRequestWithFileUrl:self.remoteUrl progress:^(int64_t bytesRead, int64_t totalBytes) {
+    } success:^(NSURL * _Nonnull fileUrl) {
+        [self configImageWallWithPath:fileUrl];
+    } faliure:^(NSError * _Nonnull error) {
+        [LOADING_MANAGER removeCustomLoading];
+    }];
 }
 
 - (void)changeLandScape {
@@ -86,14 +115,13 @@
 }
 
 - (void)configWithVideoPath:(NSURL *)videoPathUrl {
-    [self configImageWallWithPath:videoPathUrl];
+    self.videoUrl = videoPathUrl;
 }
 
 - (void)configImageWallWithPath:(NSURL *)fileUrl {
     self.videoUrl = fileUrl;
     AVAsset * asset =[AVAsset assetWithURL:fileUrl];
     NSMutableArray * times = [NSMutableArray arrayWithCapacity:0];
-    CGFloat videoTime = CMTimeGetSeconds(asset.duration);
 
     for (int i = 0; i < COVER_COUNT; i++) {
         
@@ -140,6 +168,7 @@
 }
 
 - (void)updateStatus:(id)sender {
+    [LOADING_MANAGER removeCustomLoading];
     self.imageSlider.maximumValue = _imageArray.count;
     UIImage *firstImage = [self.imageArray firstObject];
     self.imageSlider.imageArray = [self.imageArray copy];
@@ -149,16 +178,7 @@
 }
 
 - (void)configWithVideoRemoteUrl:(NSString *)remoteUrl {
-    [LOADING_MANAGER showCustomLoading:@"资源下载中..."];
-    [KSNetworkingManager downloadFileRequestWithFileUrl:remoteUrl progress:^(int64_t bytesRead, int64_t totalBytes) {
-
-    } success:^(NSURL * _Nonnull fileUrl) {
-        [LOADING_MANAGER removeCustomLoading];
-        [self configImageWallWithPath:fileUrl];
-        
-    } faliure:^(NSError * _Nonnull error) {
-        [LOADING_MANAGER removeCustomLoading];
-    }];
+    self.remoteUrl = remoteUrl;
 }
 
 - (void)chooseCropImageCallback:(VideoCropCallback)callback {
@@ -223,9 +243,7 @@
                 [weakSelf backAction];
             }
             else {
-                if (weakSelf.needChangeOrigin) {
-                    [weakSelf changeOrientation:NO];
-                }
+                
                 if (weakSelf.callback) {
                     weakSelf.callback(weakSelf.displayImage.image);
                 }
@@ -238,7 +256,11 @@
 
 
 - (void)backAction {
+    
     [self dismissViewControllerAnimated:YES completion:nil];
+    if (self.needChangeOrigin) {
+        [self changeOrientation:NO];
+    }
 }
 /*
 #pragma mark - Navigation

+ 17 - 1
KulexiuForTeacher/KulexiuForTeacher/Module/Mine/Works/View/KSVideoImageSlider.m

@@ -29,6 +29,7 @@
         // Initialization code
         _maximumValue = 10.0;
         _minimumValue = 0.0;
+        _previousTouchPoint = CGPointMake(0, 0);
        // _knobValue = 0.0;
         [self createLayerView:frame];
         [self createTheknob];
@@ -94,8 +95,23 @@
 }
 #pragma mark -----------TouchHandle
 - (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event{
-    _previousTouchPoint = [touch locationInView:self];
+    CGPoint touchPoint = [touch locationInView:self];
+    
+    // 1. determine by how much the user has dragged
+    float delta = touchPoint.x - _previousTouchPoint.x;
+    float valueDelta = (_maximumValue - _minimumValue) * delta / _useableTrackLength;
+    
+    _previousTouchPoint = touchPoint;
+    
+    _knobValue  += valueDelta;
+    _knobValue  = BOUND(_knobValue, _maximumValue, _minimumValue);
+    [CATransaction begin];
+    [CATransaction setDisableActions:YES] ;
     
+    [self setKnodFrames];
+    
+    [CATransaction commit];
+    [self sendActionsForControlEvents:UIControlEventValueChanged];
     return YES;
 }
 - (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event{

+ 1 - 0
KulexiuForTeacher/KulexiuForTeacher/Module/Mine/Works/View/MusicPubHeader.h

@@ -13,6 +13,7 @@ typedef NS_ENUM(NSInteger, PUBLISH_ACTION) {
     PUBLISH_ACTION_PUBLISH,    // 发布
     PUBLISH_ACTION_VIDEOCOVER, // 选择视频封面
     PUBLISH_ACTION_VIDEOCROP,  // 截取视频封面
+    PUBLISH_ACTION_CANCLE,     // 取消发布
 };
 
 typedef void(^MusicPublishCallback)(PUBLISH_ACTION type);

+ 3 - 1
KulexiuForTeacher/KulexiuForTeacher/Module/Mine/Works/View/MusicPublistAlert.m

@@ -73,7 +73,6 @@
         // container
         self.publishContainView = [MusicPublicContentView shareInstance];
         [self addSubview:self.publishContainView];
-        CGFloat height = [MusicPublicContentView getViewHeight];
         [self.publishContainView mas_makeConstraints:^(MASConstraintMaker *make) {
             make.left.right.top.bottom.mas_equalTo(self.containerView);
         }];
@@ -103,6 +102,9 @@
 
 
 - (IBAction)cancleAction:(id)sender {
+    if (self.callback) {
+        self.callback(PUBLISH_ACTION_CANCLE);
+    }
     [self hideAlert];
 }