Browse Source

1.调整录制进度

wenweiwei 3 years ago
parent
commit
97948c9b32

+ 21 - 9
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -967,12 +967,12 @@ public class BFRecordScreenController: BFBaseViewController {
                     indirectionView?.deleteItem(index: modelIndex)
                     // 删除对应字幕
                     let deleteTitiles = deleteTitles(voiceModel: model)
-                    for title in deleteTitiles{
+                    for title in deleteTitiles {
                         itemModels[currItemModelIndex].titleStickers.removeAll { model in
                             title.0.timelineIn == model.timelineIn
                         }
-                    } 
-                    //恢复被覆盖的音频
+                    }
+                    // 恢复被覆盖的音频
                     var tuples = action.deletedVoices
                     if tuples != nil, tuples!.count > 0 {
                         tuples!.sort { tuple1, tuple2 in
@@ -982,7 +982,7 @@ public class BFRecordScreenController: BFBaseViewController {
                             itemModels[currItemModelIndex].voiceStickers.insert(tuple.0, at: tuple.1)
                         }
                     }
-                    //恢复被覆盖的字幕
+                    // 恢复被覆盖的字幕
                     let titleTuples = action.deletedTittles
                     if titleTuples != nil, titleTuples!.count > 0 {
                         titleTuples?.forEach { titleTuple in
@@ -1313,13 +1313,12 @@ public class BFRecordScreenController: BFBaseViewController {
         }
     }
 
-    
     /// 图片素材录音的播放
     /// - Parameters:
     ///   - currentT: <#currentT description#>
     ///   - shouldPlayRecordIndex: <#shouldPlayRecordIndex description#>
     ///   - recordedAudio: <#recordedAudio description#>
-    func imageMaterialRecordPlay(at currentT: CMTime, shouldPlayRecordIndex: Int, recordedAudio: PQVoiceModel) {
+    func imageMaterialRecordPlay(at currentT: CMTime, shouldPlayRecordIndex _: Int, recordedAudio: PQVoiceModel) {
         synced(currentPlayRecordIndex) { [weak self] in
             guard let sself = self else {
                 return
@@ -1351,6 +1350,7 @@ public class BFRecordScreenController: BFBaseViewController {
             }
         }
     }
+
     func play() {
         BFLog(1, message: "开始播放 \(currentAssetProgress.seconds)")
 
@@ -1584,8 +1584,14 @@ public class BFRecordScreenController: BFBaseViewController {
 
     func drawProgressIndication(progress: Double) {
         if indirectionView == nil {
-            indirectionView = BFIndirectionProgressView(frame: progressThumV.progessIndicateBackV.bounds, percenWidth: itemModels[currItemModelIndex].mediaType == .IMAGE ? progressThumV.thumbImageWidth / 2 : 0, totalDuration: itemModels[currItemModelIndex].materialDuraion)
-            progressThumV.progessIndicateBackV.addSubview((indirectionView)!)
+            var percenWidth: CGFloat = 0
+            if itemModels[currItemModelIndex].mediaType == .IMAGE {
+                percenWidth = progressThumV.thumbImageWidth / 2.0
+            } else {
+                percenWidth = progressThumV.progessIndicateBackV.frame.width / CGFloat(itemModels[currItemModelIndex].materialDuraion)
+            }
+            indirectionView = BFIndirectionProgressView(frame: CGRect(origin: progressThumV.progessIndicateBackV.origin, size: CGSize(width: progressThumV.progressView.contentSize.width, height: progressThumV.progessIndicateBackV.frame.height)), percenWidth: percenWidth, totalDuration: itemModels[currItemModelIndex].materialDuraion)
+            progressThumV.progressView.addSubview((indirectionView)!)
         }
         // 更新录制进度
         // 注:视频无法以录制进度驱动,因当录音开始录音时播放器还未播放,导致进度不一致
@@ -1718,7 +1724,13 @@ extension BFRecordScreenController: UICollectionViewDelegate, UICollectionViewDa
             // 重绘录音区域
             progressThumV.recordItem = recordItem
             DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in
-                self?.indirectionView?.resetAllSubViews(items: recordItem.voiceStickers, percenWidth: recordItem.mediaType == .IMAGE ? (self?.progressThumV.thumbImageWidth ?? 0) / 2.0 : 0, totalDuration: recordItem.materialDuraion)
+                var percenWidth: CGFloat = 0
+                if recordItem.mediaType == .IMAGE {
+                    percenWidth = (self?.progressThumV.thumbImageWidth ?? 0) / 2.0
+                } else {
+                    percenWidth = (self?.progressThumV.progessIndicateBackV.frame.width ?? 0) / CGFloat(recordItem.materialDuraion)
+                }
+                self?.indirectionView?.resetAllSubViews(items: recordItem.voiceStickers, percenWidth: percenWidth, totalDuration: recordItem.materialDuraion)
             }
             // 更新缩略图
             progressThumV.isHidden = false

+ 2 - 5
BFRecordScreenKit/Classes/RecordScreen/View/BFIndirectionProgressView.swift

@@ -52,12 +52,9 @@ class BFIndirectionProgressView: UIView {
     /// - Parameter items: <#items description#>
     ///  - Parameter  percenWidth: 图片为固定值要传入,视频的话可以计算,也可以传入
     func resetAllSubViews(items: [PQVoiceModel]?, percenWidth: CGFloat = 0, totalDuration: Float64) {
-        frame.size.width = superview?.bounds.width ?? 0
+        frame.size.width = (superview as? UIScrollView)?.contentSize.width ?? 0
         self.totalDuration = totalDuration
         self.percenWidth = percenWidth
-        if self.percenWidth <= 0, totalDuration > 0 {
-            self.percenWidth = frame.width / totalDuration
-        }
         subviews.forEach { vv in
             vv.removeFromSuperview()
         }
@@ -75,7 +72,7 @@ class BFIndirectionProgressView: UIView {
     func setProgress(start: CGFloat = 0, progress: Float64) {
         BFLog(message: "录音进度--指示器Indir:progress=\(progress),duration=\(totalDuration),w=\(frame.width),perW=\(percenWidth),totalW:\(progress * percenWidth)")
         if start * percenWidth >= frame.width {
-            frame.size.width = superview?.bounds.width ?? 0
+            frame.size.width = (superview as? UIScrollView)?.contentSize.width ?? 0
         }
         detectionAndCreateItem(start: start, progress: progress)
         currentItem?.frame.size.width = progress < 0 ? 0 : progress * percenWidth