Kaynağa Gözat

modify: 取消卡点 视频处理中 弹窗修改

Melody 5 yıl önce
ebeveyn
işleme
a35ab0ebfd

+ 23 - 68
SuperShow/UI/Template/WSSTemplateSpotViewController.swift

@@ -83,7 +83,6 @@ class WSSTemplateSpotViewController: WSSMultiVideoEditViewController {
     fileprivate var exportSession: AVAssetExportSession?
 
     fileprivate var exportTimer: Timer?
-    fileprivate var combineSessionDisplayLink: CADisplayLink?
 
     /// transitionExport 在主动取消后,还是会调用 updateProgress所以用这个属性处理一下
     fileprivate var isUserCancel = false
@@ -179,8 +178,6 @@ class WSSTemplateSpotViewController: WSSMultiVideoEditViewController {
             return
         }
 
-        stopCombineSessionDisplay()
-
         playerContainView.removeAllSubViews()
         subVideoContainerView.removeAllSubViews()
         transitionAlert.removeAllSubViews()
@@ -698,9 +695,9 @@ extension WSSTemplateSpotViewController {
 
             let presentName = WSSMediaOperationTool.resolvePresentName(forVideoAsset: combineResult.0)
             // 混音
-//            if isShowHub {
-//                WSSHub.showHub("视频处理中...")
-//            }
+            if isShowHub {
+                WSSHub.showHub("视频处理中...")
+            }
 
             if let session = self.combineSession, session.status == .exporting || session.status == .waiting {
                 session.cancelExport()
@@ -715,27 +712,28 @@ extension WSSTemplateSpotViewController {
                                                                 presetName: presentName,
                                                                 videoComposition: combineResult.1,
                                                                 exportPath: outputPath,
-                                                                finish: { [weak self] resultAsset in
-                                                                    DispatchQueue.main.async(execute: { [unowned self] in
+                                                                finish: { [unowned self] resultAsset in
 
-                                                                        if isShowHub {
-                                                                            self?.combineSessionDisplayLink?.isPaused = true
-                                                                            hideHud()
-                                                                        }
-                                                                        self?.isNeedCombineVideo = false
+                                                                    if isShowHub {
+                                                                        WSSHub.dismissHub()
+                                                                    }
+                                                                    self.combineSession = nil
+                                                                    self.isNeedCombineVideo = false
+
+                                                                    if resultAsset != nil {
+                                                                        DispatchQueue.main.async(execute: { [unowned self] in
 
-                                                                        if resultAsset != nil {
-                                                                            let status = self!.mainVideoPlayer?.playerStatus
+                                                                            let status = self.mainVideoPlayer?.playerStatus
                                                                             let playItem = AVPlayerItem(asset: resultAsset!)
                                                                             playItem.audioTimePitchAlgorithm = .spectral
-                                                                            self!.resetVideo(withPlayItem: playItem, readyToPlayCallBack: {
+                                                                            self.resetVideo(withPlayItem: playItem, readyToPlayCallBack: {
                                                                                 if let callBack = readyToPlayCallBack {
                                                                                     callBack()
                                                                                 }
 
                                                                             })
-                                                                            self!.startVideo()
-                                                                            if status == .playing && self!.currentPlayMode() == true {
+                                                                            self.startVideo()
+                                                                            if status == .playing && self.currentPlayMode() == true {
                                                                                 // 当有正在播放的主视频时,合成了一个新的,这时候需要重新出发播放
                                                                                 // 切换播放状态需要稍微延迟一点点
                                                                                 DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3, execute: { [weak self] in
@@ -747,7 +745,7 @@ extension WSSTemplateSpotViewController {
                                                                                 // 添加关键点
                                                                                 var progressArray: [CGFloat] = []
                                                                                 var total: TimeInterval = 0.0
-                                                                                for info in self!.spotVideoInfoArray {
+                                                                                for info in self.spotVideoInfoArray {
                                                                                     let pg = (info.selectedTimeRange.duration.seconds + total) / resultAsset!.duration.seconds
                                                                                     progressArray.append(CGFloat(pg))
 
@@ -756,25 +754,16 @@ extension WSSTemplateSpotViewController {
                                                                                 // 去掉最后一项
                                                                                 progressArray.removeLast()
 
-                                                                                self!.videoProgressView.setupKeyPoints(withProgress: progressArray)
-                                                                            }
-
-                                                                        } else {
-                                                                            if isShowHub {
-                                                                                self?.combineSessionDisplayLink?.isPaused = true
-                                                                                hideHud()
-                                                                                showHud(withOnlyText: "视频加载失败,稍后重试")
+                                                                                self.videoProgressView.setupKeyPoints(withProgress: progressArray)
                                                                             }
+                                                                        })
+                                                                    } else {
+                                                                        if isShowHub {
+                                                                            showHud(withOnlyText: "视频加载失败,稍后重试")
                                                                         }
-                                                                    })
+                                                                    }
             })
 
-            if isShowHub {
-                setupCombineSessionDisplayLink()
-            } else {
-                combineSessionDisplayLink?.isPaused = true
-            }
-
         } catch {
             if isShowHub {
                 showHud(withOnlyText: "视频加载失败,稍后重试")
@@ -955,8 +944,6 @@ extension WSSTemplateSpotViewController {
         mainVideoPlayer?.play()
     }
 
-    // MARK: exportSession
-
     private func showExportProgress() {
         exportTimer?.invalidate()
         exportTimer = nil
@@ -991,38 +978,6 @@ extension WSSTemplateSpotViewController {
         hideHud()
     }
 
-    // MARK: combineSessionDisplayLink
-
-    func setupCombineSessionDisplayLink() {
-        /// 因为combineVideo会频繁调用,所以不直接删除了
-        if combineSessionDisplayLink == nil {
-            let displayLink = CADisplayLink(target: self, selector: #selector(updateCombineSessionProgress))
-            DispatchQueue.main.async {
-                displayLink.add(to: .current, forMode: .common)
-                self.combineSessionDisplayLink = displayLink
-            }
-        } else {
-            combineSessionDisplayLink?.isPaused = false
-        }
-    }
-
-    func stopCombineSessionDisplay() {
-        if let displayLink = combineSessionDisplayLink {
-            displayLink.isPaused = true
-            displayLink.invalidate()
-            combineSessionDisplayLink = nil
-        }
-    }
-
-    @objc func updateCombineSessionProgress() {
-        if let exportSession = combineSession {
-            let progress = simd_clamp(exportSession.progress, 0.0, 1.0)
-            showProgressHud(progress: progress, status: "视频处理中...")
-        } else {
-            combineSessionDisplayLink?.isPaused = true
-        }
-    }
-
     private func combineTransition(withVideoUrl videoUrl: URL) {
         // 如果没有设置过转场,则直接输出
         guard localTransitionDic.keys.count > 0 else {