Przeglądaj źródła

1.重置图片素材回退进度

wenweiwei 3 lat temu
rodzic
commit
7a664b5cc6

+ 20 - 14
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -88,17 +88,17 @@ public class BFRecordScreenController: BFBaseViewController {
     // MARK: 行为参数
 
     var movieIsProcessing = false
-    
+
     // 行为记录,方便撤销
     var events = [WithDrawModel]() {
         didSet {
             withDrawBtn.isEnabled = (events.count != 0)
         }
     }
-    
+
     // 是否在拖动进度条
     var isDragingProgressSlder: Bool = false
-    
+
     var isStopAtRecordRange = -1
 
     // 保存识别出来的字幕信息,用于回放,和合成使用
@@ -987,15 +987,15 @@ public class BFRecordScreenController: BFBaseViewController {
                 if itemModels[currItemModelIndex].mediaType == .IMAGE {
                     itemModels[currItemModelIndex].materialDuraion = itemModels[currItemModelIndex].voiceStickers.last?.endTime ?? 0
                 }
-                
+
             } else {}
             events.removeLast()
 
             let dur = itemModels[currItemModelIndex].materialDuraion
             if dur > 0 {
-                changeProgress(progress: Float(jumpTime / dur))
+                changeProgress(isBack: true, progress: itemModels[currItemModelIndex].mediaType == .IMAGE ? Float(jumpTime) : Float(jumpTime / dur))
             } else {
-                changeProgress(progress: Float(0))
+                changeProgress(isBack: true, progress: Float(0))
             }
             isDragingProgressSlder = false
             currentPlayRecordIndex = -1
@@ -1008,8 +1008,12 @@ public class BFRecordScreenController: BFBaseViewController {
                 changeWithDrawBtnLayout(false)
             }
             searchStopAtRecordRange()
+            // 重置进度条
             indirectionView?.resetAllSubViews(items: itemModels[currItemModelIndex].voiceStickers, percenWidth: progressThumV.thumbImageWidth / 2.0, totalDuration: itemModels[currItemModelIndex].materialDuraion)
-
+            // 如果是图片需重置播放按钮
+            if itemModels[currItemModelIndex].mediaType == .IMAGE {
+                (collectionView.cellForItem(at: IndexPath(item: currItemModelIndex, section: 0)) as? BFImageCoverViewCell)?.playBtn.isSelected = itemModels[currItemModelIndex].voiceStickers.count <= 0
+            }
         }
     }
 
@@ -1463,7 +1467,11 @@ public class BFRecordScreenController: BFBaseViewController {
     }
 
     // 通过缩略图进度条控制播放进度
-    func changeProgress(progress: Float) {
+    func changeProgress(isBack: Bool = false, progress: Float) {
+        // 偶现拖动过程回调中process为NaN情况
+        guard !progress.isNaN else {
+            return
+        }
         if itemModels[currItemModelIndex].mediaType == .VIDEO {
             if let duration = assetPlayer?.currentItem?.duration {
                 currentAssetProgress = CMTime(value: CMTimeValue(progress * Float(CMTimeGetSeconds(duration)) * 1000), timescale: 1000)
@@ -1474,13 +1482,11 @@ public class BFRecordScreenController: BFBaseViewController {
                 }
             }
         } else {
-            if itemModels[currItemModelIndex].materialDuraion >= 0 {
-                currentAssetProgress = CMTime(value: CMTimeValue(progress * Float(itemModels[currItemModelIndex].materialDuraion) * 1000), timescale: 1000)
-                DispatchQueue.main.async { [weak self] in
-                    self?.progreddL.text = String(format: "%@", CMTimeGetSeconds(self!.currentAssetProgress).formatDurationToHMS())
-                }
-                BFLog(message: "progress = \(progress),currentAssetProgress = \(currentAssetProgress.seconds),materialDuraion = \(itemModels[currItemModelIndex].materialDuraion)")
+            currentAssetProgress = isBack ? CMTime(value: CMTimeValue(progress * 1000), timescale: 1000) : CMTime(value: CMTimeValue(progress * Float(itemModels[currItemModelIndex].materialDuraion) * 1000), timescale: 1000)
+            DispatchQueue.main.async { [weak self] in
+                self?.progreddL.text = String(format: "%@", CMTimeGetSeconds(self!.currentAssetProgress).formatDurationToHMS())
             }
+            BFLog(message: "progress = \(progress),currentAssetProgress = \(currentAssetProgress.seconds),materialDuraion = \(itemModels[currItemModelIndex].materialDuraion)")
         }
     }
 

+ 9 - 24
BFRecordScreenKit/Classes/RecordScreen/View/BFVideoThumbProgressView.swift

@@ -251,55 +251,40 @@ class BFVideoThumbProgressView: UIView {
 
 extension BFVideoThumbProgressView: UIScrollViewDelegate {
     func scrollViewDidScroll(_ scrollView: UIScrollView) {
+        let totalW = recordItem?.mediaType == .VIDEO ? (scrollView.contentSize.width - width) :  (CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0)
         if recordItem?.mediaType == .VIDEO {
             if isDrag {
-                let dur = scrollView.contentOffset.x / (scrollView.contentSize.width - width)
-                dragScrollProgressHandle?(false, Float(dur))
+                dragScrollProgressHandle?(false, totalW > 0 ? Float((scrollView.contentOffset.x / totalW)) : 0)
             }
         } else if recordItem?.mediaType == .IMAGE {
             if isDrag {
                 if scrollView.contentOffset.x > CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0 {
                     scrollView.contentOffset = CGPoint(x: CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0, y: 0)
                 }
-                let dur = scrollView.contentOffset.x / (CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0)
-                dragScrollProgressHandle?(false, Float(dur))
+                dragScrollProgressHandle?(false, totalW > 0 ? Float((scrollView.contentOffset.x / totalW)) : 0)
             }
         }
     }
 
     func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
         isDrag = true
-        var dur: CGFloat = 0
-        if recordItem?.mediaType == .VIDEO {
-            dur = scrollView.contentOffset.x / (scrollView.contentSize.width - width)
-        } else {
-            dur = scrollView.contentOffset.x / (CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0)
-        }
+        let totalW = recordItem?.mediaType == .VIDEO ? (scrollView.contentSize.width - width) :  (CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0)
         dragStartHandle?()
-        dragScrollProgressHandle?(true, Float(dur))
+        dragScrollProgressHandle?(true, totalW > 0 ? Float((scrollView.contentOffset.x / totalW)) : 0)
     }
 
     func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
         if !decelerate {
-            var dur: CGFloat = 0
-            if recordItem?.mediaType == .VIDEO {
-                dur = scrollView.contentOffset.x / (scrollView.contentSize.width - width)
-            } else {
-                dur = scrollView.contentOffset.x / (CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0)
-            }
+            let totalW = recordItem?.mediaType == .VIDEO ? (scrollView.contentSize.width - width) :  (CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0)
             isDrag = false
-            dragEndHandle?(Float(dur))
+            dragEndHandle?(totalW > 0 ? Float((scrollView.contentOffset.x / totalW)) : 0)
         }
     }
 
     func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
         var dur: CGFloat = 0
-        if recordItem?.mediaType == .VIDEO {
-            dur = scrollView.contentOffset.x / (scrollView.contentSize.width - width)
-        } else {
-            dur = scrollView.contentOffset.x / (CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0)
-        }
+        let totalW = recordItem?.mediaType == .VIDEO ? (scrollView.contentSize.width - width) :  (CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0)
         isDrag = false
-        dragEndHandle?(Float(dur))
+        dragEndHandle?(totalW > 0 ? Float((scrollView.contentOffset.x / totalW)) : 0)
     }
 }