소스 검색

音乐波形纹的绘制 优化

huzhiqiang 3 년 전
부모
커밋
20dde6e280

+ 6 - 2
BFFramework/Classes/Stuckpoint/Controller/PQStuckPointEditerController.swift

@@ -1029,8 +1029,12 @@ class PQStuckPointEditerController: PQBaseViewController {
                 BFLog(message: " playerView.play tiskskskskme  \(end4 - end3)")
 
                 // 6,进度回调
-                self.playerView.progress = { [weak self] currentTime, tatolTime, _ in
-                    
+                self.playerView.progress = { [weak self] currentTime, tatolTime, percent in
+                    if percent == 1 {
+                        self?.stuckPointCuttingView.resetDefaultsColor(clearData: false)
+
+                        return
+                    }
                     if(CMTimeGetSeconds(self?.playeTimeRange.duration ?? .zero) <= 0.0){
                         BFLog(message: "时长错误!!!!")
                         return

+ 19 - 6
BFFramework/Classes/Stuckpoint/View/PQStuckPointCuttingView.swift

@@ -58,6 +58,7 @@ class PQStuckPointCuttingView: UIView {
     private var oneMarginTime: CGFloat = 0
 
     private var isDrawLine: Bool = false
+    private var startDraw = true
 
     // 保存已经绘制的竖线用于变色使用
     var lineLayerArray: Array = Array<CAShapeLayer>.init()
@@ -290,22 +291,32 @@ class PQStuckPointCuttingView: UIView {
     /// progress <#progress description#>
     func updateProgress(progress: CGFloat) {
         
-
         if(progress <= 0 || lineLayerArray.count == 0 || progress.isNaN){
             BFLog(message: "progress is error ")
             return
         }
         
-        BFLog(message: "progress is Start ************* ")
-
         let startIndex = scrollView.contentOffset.x / (frequencyWidth + frequencyMargin)
-        let selectIndex = Int(floor(startIndex + progress * CGFloat(wavSelectCount)))
+        if startDraw { // 第一个波纹
+            startDraw = false
+            let selectIndex = Int(ceil(startIndex))
+            if(selectIndex < lineLayerArray.count){
+                let drawLayer:CAShapeLayer = lineLayerArray[selectIndex]
+                if drawLayer.strokeColor != UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue).cgColor{
+                    drawLayer.strokeColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue).cgColor
+                    drawLayer.setNeedsDisplay()
+                    drawLayer.layoutIfNeeded()
+                }
+            }
+        }
+        let selectIndex = Int(ceil(startIndex + progress * CGFloat(wavSelectCount)))
         if(selectIndex < lineLayerArray.count){
             let drawLayer:CAShapeLayer = lineLayerArray[selectIndex]
 //            BFLog(1, message: "progress is \(progress) i \(selectIndex) 命中的位置:\(CGFloat(selectIndex) * oneMarginTime)")
             if drawLayer.strokeColor != UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue).cgColor{
                 drawLayer.strokeColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue).cgColor
                 drawLayer.setNeedsDisplay()
+                drawLayer.layoutIfNeeded()
             }
         }
 
@@ -319,6 +330,8 @@ class PQStuckPointCuttingView: UIView {
 
     // 竖线恢复到原有色值
     func resetDefaultsColor(clearData:Bool = true) {
+        startDraw = false
+
         for layer in lineLayerArray {
             layer.strokeColor = UIColor.hexColor(hexadecimal: "#999999").cgColor
             layer.setNeedsDisplay()
@@ -365,9 +378,9 @@ class PQStuckPointCuttingView: UIView {
             lineLayer.path = linePath.cgPath
             lineLayer.fillColor = UIColor.black.cgColor
 
-            // 推荐的开始起点是虚线
+            // 推荐的开始起点是虚线 减0.0001因为精度问题
 //            BFLog(1, message: "suggestRhythmStartTime is \(suggestRhythmStartTime)")
-            if oneMarginTime * CGFloat(i) >= suggestRhythmStartTime && !isDrawLine {
+            if oneMarginTime * CGFloat(i) >= (suggestRhythmStartTime-0.0001) && !isDrawLine {
                 isDrawLine = true
                 linePath.move(to: CGPoint(x: originX, y: -10))
                 // 终点

+ 2 - 1
BFFramework/Classes/Stuckpoint/ViewModel/PQGPUImagePlayerView.swift

@@ -454,6 +454,7 @@ public class PQGPUImagePlayerView: UIView {
                 strongSelf.status = .stop
                 strongSelf.finishedClosure?()
                 strongSelf.showPlayBtn(isHidden: false)
+                strongSelf.progress!(0,0,1)
             }
         }
         speaker = SpeakerOutput()
@@ -567,7 +568,7 @@ public class PQGPUImagePlayerView: UIView {
           
             FilterLog(message: "缓存没有查找到?出现数据错误!!!!")
             for (index,bsFilter )in cacheFilters.enumerated() {
-                BFLog(1, message: "22222缓存操作   没要查找到要查找的显示是为:\(currTime) 缓存数据timeline in :\(bsFilter.stickerInfo?.timelineIn ?? 0.0)) timelineOut:\(bsFilter.stickerInfo?.timelineOut ?? 0.0) 缓存数 \(cacheFilters.count) index: \(index)")
+                BFLog(2, message: "22222缓存操作   没要查找到要查找的显示是为:\(currTime) 缓存数据timeline in :\(bsFilter.stickerInfo?.timelineIn ?? 0.0)) timelineOut:\(bsFilter.stickerInfo?.timelineOut ?? 0.0) 缓存数 \(cacheFilters.count) index: \(index)")
             }
             
             return