Browse Source

修改音频剪切的误差问题

huzhiqiang 3 năm trước cách đây
mục cha
commit
bafc75e563

+ 14 - 9
BFFramework/Classes/Stuckpoint/View/PQStuckPointCuttingView.swift

@@ -189,18 +189,20 @@ class PQStuckPointCuttingView: UIView {
 
     func addData() {
         // 1,选择区内的线个数 ,划动区域后 个数会变???
-        wavSelectCount = Int(cropViewWidth / (frequencyWidth + frequencyMargin))
+        wavSelectCount = Int(ceil(cropViewWidth / (frequencyWidth + frequencyMargin)))
+        
+        cropViewWidth = CGFloat(wavSelectCount) * (frequencyWidth + frequencyMargin) + frequencyWidth
      
         // 2竖线一个间隔代表多少 S 是动态的
-        oneMarginTime = (stuckPointEndTime - stuckPointStartTime) / CGFloat(wavSelectCount)
+        oneMarginTime = (stuckPointEndTime - stuckPointStartTime) / CGFloat(wavSelectCount - 1)
         
         // 3,一共绘制的竖线个数
-        wavTotalCount = Int(videoDuration / oneMarginTime)
+        wavTotalCount = Int(ceil(videoDuration / oneMarginTime))
 
         timeRange = oneMarginTime * 10
         // 显示时间 label 的个数 , -1 不够整倍数就不显示时间了
         let timeLabelCount = Int(wavTotalCount / 10)
-        contentWidth = CGFloat(wavTotalCount) * (frequencyWidth + frequencyMargin) + margin * 2 + timeLineWidth / 2
+        contentWidth = CGFloat(wavTotalCount) * (frequencyWidth + frequencyMargin) + frequencyWidth + (cScreenWidth - cropViewWidth)
         if contentWidth < scrollView.frame.width {
             contentWidth = scrollView.frame.width
         }
@@ -264,14 +266,17 @@ class PQStuckPointCuttingView: UIView {
             BFLog(message: "progress is error ")
             return
         }
-        let startIndex = stuckPointStartTime / oneMarginTime
-        BFLog(message: "startIndex is\(startIndex) stuckPointStartTime is: \(stuckPointStartTime)")
-        let selectIndex = Int(startIndex + progress * CGFloat(wavSelectCount))
+        let startIndex = scrollView.contentOffset.x / (frequencyWidth + frequencyMargin)
+        
+//        HHZPrint("startIndex is:\(startIndex) stuckPointStartTime is: \(stuckPointStartTime)")
+        let selectIndex = Int(ceil(startIndex + progress * CGFloat(wavSelectCount)))
         if(selectIndex < lineLayerArray.count){
             let drawLayer:CAShapeLayer = lineLayerArray[selectIndex]
             BFLog(message: "progress is \(progress) i \(selectIndex) 命中的位置:\(CGFloat(selectIndex) * oneMarginTime)")
-            drawLayer.strokeColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue).cgColor
-            drawLayer.setNeedsDisplay()
+            if drawLayer.strokeColor != UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue).cgColor{
+                drawLayer.strokeColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue).cgColor
+                drawLayer.setNeedsDisplay()
+            }
         }