Forráskód Böngészése

update image progress

wenweiwei 3 éve
szülő
commit
7a1096fdb5

+ 13 - 6
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -119,7 +119,12 @@ public class BFRecordScreenController: BFBaseViewController {
                 }
                 sself.itemModels[sself.currItemModelIndex].voiceStickers.append(model)
                 if sself.itemModels[sself.currItemModelIndex].mediaType == .IMAGE {
-                    sself.itemModels[sself.currItemModelIndex].materialDuraion = sself.itemModels[sself.currItemModelIndex].materialDuraion + (Double(model.duration ?? "0") ?? 0)
+                    var duration: Double = 0
+                    sself.itemModels[sself.currItemModelIndex].voiceStickers.forEach { item in
+                        duration = duration + (Double(model.duration ?? "0") ?? 0)
+                    }
+                    sself.itemModels[sself.currItemModelIndex].materialDuraion = duration
+                    sself.currentAssetProgress = CMTime(seconds: duration, preferredTimescale: 1000)
                 }
                 sself.drawOrUpdateRecordProgessLable()
 
@@ -934,7 +939,7 @@ public class BFRecordScreenController: BFBaseViewController {
             return
         }
 
-        BFLog(1, message: "当前时间:\(CMTimeGetSeconds(currentT)), 找到的音频:\(recordedAudio.startTime), \(recordedAudio.endTime)")
+        BFLog(1, message: "当前时间:\(CMTimeGetSeconds(currentT)), 找到的音频:\(recordedAudio.startTime), \(recordedAudio.endTime),, \(recordedAudio.wavFilePath)")
 
         // 创建播放器
         if recordPlayer == nil || (recordPlayer?.currentItem?.asset as? AVURLAsset)?.url.lastPathComponent != (recordedAudio.wavFilePath as NSString).lastPathComponent {
@@ -1185,6 +1190,9 @@ 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)")
             }
         }
@@ -1369,11 +1377,10 @@ public extension BFRecordScreenController {
     func imageRecordProgress(progress: Float64) {
         BFLog(message: "图片录音进度:\(progress)")
         if itemModels[currItemModelIndex].mediaType == .IMAGE {
-            currentAssetProgress = CMTime(seconds: progress, preferredTimescale: 1000)
             DispatchQueue.main.async { [weak self] in
-                self?.progreddL.text = String(format: "%@", progress.formatDurationToHMS())
-                self?.progressThumV.progress = progress
-                self?.updateSubtitle(time: CMTime(value: CMTimeValue(progress), timescale: 1))
+                self?.progreddL.text = String(format: "%@", (progress + (self?.currentAssetProgress.seconds ?? 0)).formatDurationToHMS())
+                self?.progressThumV.progress = (progress + (self?.currentAssetProgress.seconds ?? 0))
+                self?.updateSubtitle(time: CMTime(value: CMTimeValue((progress + (self?.currentAssetProgress.seconds ?? 0))), timescale: 1))
             }
         }
     }

+ 4 - 4
BFRecordScreenKit/Classes/RecordScreen/View/BFVideoThumbProgressView.swift

@@ -179,7 +179,7 @@ extension BFVideoThumbProgressView: UIScrollViewDelegate {
                 scrollView.contentOffset = CGPoint(x: CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0, y: 0)
             }
             if isDrag {
-                let dur = scrollView.contentOffset.x / thumbImageWidth / 2
+                let dur = scrollView.contentOffset.x / (CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0)
                 dragScrollProgressHandle?(false, Float(dur))
             }
         }
@@ -191,7 +191,7 @@ extension BFVideoThumbProgressView: UIScrollViewDelegate {
         if recordItem?.mediaType == .VIDEO {
             dur = scrollView.contentOffset.x / (scrollView.contentSize.width - width)
         } else {
-            dur = scrollView.contentOffset.x / thumbImageWidth / 2
+            dur = scrollView.contentOffset.x / (CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0)
         }
         dragStartHandle?()
         dragScrollProgressHandle?(true, Float(dur))
@@ -203,7 +203,7 @@ extension BFVideoThumbProgressView: UIScrollViewDelegate {
             if recordItem?.mediaType == .VIDEO {
                 dur = scrollView.contentOffset.x / (scrollView.contentSize.width - width)
             } else {
-                dur = scrollView.contentOffset.x / thumbImageWidth / 2
+                dur = scrollView.contentOffset.x / (CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0)
             }
             isDrag = false
             dragEndHandle?(Float(dur))
@@ -215,7 +215,7 @@ extension BFVideoThumbProgressView: UIScrollViewDelegate {
         if recordItem?.mediaType == .VIDEO {
             dur = scrollView.contentOffset.x / (scrollView.contentSize.width - width)
         } else {
-            dur = scrollView.contentOffset.x / thumbImageWidth / 2
+            dur = scrollView.contentOffset.x / (CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0)
         }
         isDrag = false
         dragEndHandle?(Float(dur))