Bladeren bron

解决增加图片跳跃的问题

harry 3 jaren geleden
bovenliggende
commit
d6b0fc57ed

+ 17 - 0
BFRecordScreenKit/Classes/BFRecordExport.swift

@@ -130,6 +130,23 @@ public class BFRecordExport {
                     }
 
                     totalDur += duration
+                    continue
+                }else if itemModel.mediaType == .Camera {
+                    videoStickers.append(contentsOf: itemModel.videoStickers)
+                    //
+                    for mod in itemModel.voiceStickers {
+                        let sticker = PQEditVisionTrackMaterialsModel()
+                        sticker.model_in = 0
+                        sticker.out = mod.endCMTime.seconds - mod.startCMTime.seconds
+                        sticker.timelineIn = totalDur + mod.startCMTime.seconds
+                        sticker.timelineOut = totalDur + mod.endCMTime.seconds
+                        sticker.aptDuration = sticker.out
+                        sticker.duration = sticker.out
+                        sticker.locationPath = mod.wavFilePath
+                        sticker.volumeGain = 100 // Float64(model.volume)
+                        voiceList.append(sticker)
+                    }
+                    
                     continue
                 }
 

+ 1 - 1
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenCameraManager.swift

@@ -237,7 +237,7 @@ extension BFRecordScreenCameraManager : GPUImageVideoCameraDelegate {
         let coculationCount = Int(dur.seconds / 5.0)
         if coculationCount >= currVideoThumImagesNum{
             if let img = imageFromBuffer(sampleBuffer){
-                BFLog(1, message: "取一张缩略图出来 \(dur.seconds)")
+                BFLog(1, message: "取一张缩略图出来 \(dur.seconds), \(recordItem?.thumbImgs.count ?? 0)")
                 recordItem?.thumbImgs.append(img)
                 videoModel.thumImgs?.append(img)
                 currVideoThumImagesNum += 1

+ 76 - 78
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -169,7 +169,7 @@ public class BFRecordScreenController: BFBaseViewController {
     var currentAssetProgress: CMTime = .zero
     {
         didSet {
-            BFLog(1, message: "currentAssetProgress=\(currentAssetProgress.seconds)")
+//            BFLog(1, message: "currentAssetProgress=\(currentAssetProgress.seconds)")
             rscurrentManager.currentAssetProgress = currentAssetProgress
         }
     } // 当前素材播放的进度
@@ -636,16 +636,85 @@ public class BFRecordScreenController: BFBaseViewController {
         }
     }
     
-    // MARK: - 录音机初始化
+    func layoutsubview() {
+        bottomeView.snp.makeConstraints { make in
+            make.left.bottom.right.equalToSuperview()
+            make.height.equalTo(adapterWidth(width: 180))
+        }
+
+        progreddL.snp.makeConstraints { make in
+            make.width.equalTo(100)
+            make.centerX.equalToSuperview()
+            make.top.equalToSuperview().offset(-5)
+            make.height.equalTo(18)
+        }
+
+        withDrawBtn.snp.makeConstraints { make in
+            make.left.equalToSuperview()
+            make.width.height.equalTo(65)
+            make.top.equalTo(88)
+        }
+        //        changeVoiceBtn.snp.makeConstraints { make in
+        //            make.right.equalToSuperview()
+        //            make.top.width.height.equalTo(withDrawBtn)
+        //        }
+
+        recordBtn.snp.makeConstraints { make in
+            make.left.equalTo(withDrawBtn.snp.right)
+            make.right.equalTo(-65)
+            make.height.equalTo(42)
+            make.top.equalTo(withDrawBtn).offset(6)
+        }
+        deleteRecordBtn.snp.makeConstraints { make in
+            make.left.equalTo(withDrawBtn.snp.right)
+            make.right.equalTo(-65)
+            make.height.equalTo(42)
+            make.top.equalTo(withDrawBtn).offset(6)
+        }
+
+        //        openCameraBtn.snp.makeConstraints { make in
+        //            make.right.equalToSuperview().offset(-12)
+        //            make.top.equalToSuperview().offset(98)
+        //            make.width.equalTo(80)
+        //            make.height.equalTo(124)
+        //        }
+        //
+        //        drawPinBtn.snp.makeConstraints { make in
+        //            make.right.equalTo(openCameraBtn)
+        //            make.top.equalTo(openCameraBtn.snp.bottom).offset(18)
+        //            make.width.equalTo(80)
+        //            make.height.equalTo(124)
+        //        }
+
+        soundSettingBtn.snp.makeConstraints { make in
+            make.right.equalToSuperview().offset(-12)
+            make.top.equalToSuperview().offset(98)
+            make.width.equalTo(40)
+            make.height.equalTo(62)
+        }
+
+        subtitleBtn.snp.makeConstraints { make in
+            make.right.equalTo(soundSettingBtn)
+            make.top.equalTo(soundSettingBtn.snp.bottom).offset(18)
+            make.width.equalTo(40)
+            make.height.equalTo(62)
+        }
+
+        withDrawBtn.imageEdgeInsets = UIEdgeInsets(top: -withDrawBtn.imageView!.height, left: 0, bottom: 0, right: -withDrawBtn.titleLabel!.width)
+        withDrawBtn.titleEdgeInsets = UIEdgeInsets(top: withDrawBtn.titleLabel!.height + 2, left: -withDrawBtn.imageView!.width, bottom: 0, right: 0)
+
+        changeVoiceBtn.imageEdgeInsets = UIEdgeInsets(top: -changeVoiceBtn.imageView!.height - 2, left: 0, bottom: 0, right: -changeVoiceBtn.titleLabel!.width)
+        changeVoiceBtn.titleEdgeInsets = UIEdgeInsets(top: changeVoiceBtn.titleLabel!.height + 2, left: -changeVoiceBtn.imageView!.width, bottom: 0, right: 0)
+    }
+    // MARK: - 录音机字幕回调相关
     func initlizeRecordManager() {
         recorderManager = BFVoiceRecordManager()
         // 录音进度
         recorderManager?.recorderProgrossHandle = { [weak self] progress in
-//            BFLog(1, message: "curr:录音进度--\(progress),\(self?.isRecording ?? false)")
             self?.drawProgressIndication(progress: (progress.isNaN || progress.isInfinite) ? 0 : progress)
         }
 
-        // 录音字幕回调
+        // MARK: 录音字幕回调
         recorderManager?.subtitleRecordHandle = { [weak self] eventCode, recordId, asrResult, audioFilePath, _ in
 //            BFLog(1, message: "eventcode:\(eventCode), recordid:\(String(describing: recordId)), asr:\(String(describing: asrResult))")
             
@@ -715,7 +784,7 @@ public class BFRecordScreenController: BFBaseViewController {
             }
         }
 
-        // MARK: -  录音结束
+        // MARK: 录音结束
         recorderManager?.endRecordHandle = { [weak self, weak recorderManager] voideModel, _ in
             if let wself = self, let model = voideModel, FileManager.default.fileExists(atPath: model.wavFilePath ?? "") {
                 // 加入到语音数组里
@@ -807,7 +876,7 @@ public class BFRecordScreenController: BFBaseViewController {
                     // 矫正进度
                     self?.resetCurrentProgress()
                     self?.deleteRecordBtn.isHidden = true
-                    self?.recordBtn.isHidden = (self?.itemModels[self?.currItemModelIndex ?? 0].mediaType == .Image && (self?.isEndPlay ?? false)) ? false : (self?.isEndPlay ?? false)
+                    self?.recordBtn.isHidden = (self?.itemModels[self?.currItemModelIndex ?? 0].mediaType != .Video && (self?.isEndPlay ?? false)) ? false : (self?.isEndPlay ?? false)
                 }
                 wself.currentPlayRecordIndex = -3 // 刚录音完,不需要播放录音
                 BFLog(3, message: "重置播放index-\(#function) = \(wself.currentPlayRecordIndex)")
@@ -929,77 +998,6 @@ public class BFRecordScreenController: BFBaseViewController {
         }
     }
 
-    func layoutsubview() {
-        bottomeView.snp.makeConstraints { make in
-            make.left.bottom.right.equalToSuperview()
-            make.height.equalTo(adapterWidth(width: 180))
-        }
-
-        progreddL.snp.makeConstraints { make in
-            make.width.equalTo(100)
-            make.centerX.equalToSuperview()
-            make.top.equalToSuperview().offset(-5)
-            make.height.equalTo(18)
-        }
-
-        withDrawBtn.snp.makeConstraints { make in
-            make.left.equalToSuperview()
-            make.width.height.equalTo(65)
-            make.top.equalTo(88)
-        }
-        //        changeVoiceBtn.snp.makeConstraints { make in
-        //            make.right.equalToSuperview()
-        //            make.top.width.height.equalTo(withDrawBtn)
-        //        }
-
-        recordBtn.snp.makeConstraints { make in
-            make.left.equalTo(withDrawBtn.snp.right)
-            make.right.equalTo(-65)
-            make.height.equalTo(42)
-            make.top.equalTo(withDrawBtn).offset(6)
-        }
-        deleteRecordBtn.snp.makeConstraints { make in
-            make.left.equalTo(withDrawBtn.snp.right)
-            make.right.equalTo(-65)
-            make.height.equalTo(42)
-            make.top.equalTo(withDrawBtn).offset(6)
-        }
-
-        //        openCameraBtn.snp.makeConstraints { make in
-        //            make.right.equalToSuperview().offset(-12)
-        //            make.top.equalToSuperview().offset(98)
-        //            make.width.equalTo(80)
-        //            make.height.equalTo(124)
-        //        }
-        //
-        //        drawPinBtn.snp.makeConstraints { make in
-        //            make.right.equalTo(openCameraBtn)
-        //            make.top.equalTo(openCameraBtn.snp.bottom).offset(18)
-        //            make.width.equalTo(80)
-        //            make.height.equalTo(124)
-        //        }
-
-        soundSettingBtn.snp.makeConstraints { make in
-            make.right.equalToSuperview().offset(-12)
-            make.top.equalToSuperview().offset(98)
-            make.width.equalTo(40)
-            make.height.equalTo(62)
-        }
-
-        subtitleBtn.snp.makeConstraints { make in
-            make.right.equalTo(soundSettingBtn)
-            make.top.equalTo(soundSettingBtn.snp.bottom).offset(18)
-            make.width.equalTo(40)
-            make.height.equalTo(62)
-        }
-
-        withDrawBtn.imageEdgeInsets = UIEdgeInsets(top: -withDrawBtn.imageView!.height, left: 0, bottom: 0, right: -withDrawBtn.titleLabel!.width)
-        withDrawBtn.titleEdgeInsets = UIEdgeInsets(top: withDrawBtn.titleLabel!.height + 2, left: -withDrawBtn.imageView!.width, bottom: 0, right: 0)
-
-        changeVoiceBtn.imageEdgeInsets = UIEdgeInsets(top: -changeVoiceBtn.imageView!.height - 2, left: 0, bottom: 0, right: -changeVoiceBtn.titleLabel!.width)
-        changeVoiceBtn.titleEdgeInsets = UIEdgeInsets(top: changeVoiceBtn.titleLabel!.height + 2, left: -changeVoiceBtn.imageView!.width, bottom: 0, right: 0)
-    }
-
     //    public override func viewWillLayoutSubviews() {
     //        super.viewWillLayoutSubviews()
     //
@@ -1569,7 +1567,7 @@ public class BFRecordScreenController: BFBaseViewController {
             recordBtn.alpha = 1
 
             isStopAtRecordRange = -1
-            BFLog(1, message: "停在了录音区间外 \(isStopAtRecordRange)")
+            BFLog(1, message: "停在了录音区间外 \(isStopAtRecordRange), currTime:\(currentAssetProgress.seconds)")
         }
         pauseTime = currentAssetProgress.seconds
     }

+ 33 - 25
BFRecordScreenKit/Classes/RecordScreen/View/ProgressView/BFCameraProgressView.swift

@@ -9,6 +9,7 @@ import Foundation
 import BFCommonKit
 import BFUIKit
 import CoreMedia
+import UIKit
 
 class BFCameraProgressView: BFProgressBaseView {
     
@@ -60,12 +61,15 @@ class BFCameraProgressView: BFProgressBaseView {
     }
     
     func updateCellWidth(index:Int, progress:CMTime){
-        if let count = recordItem?.thumbImgs.count, count > 0 {
-            collectionV.reloadItems(at: [IndexPath(row: count - 1, section: 0)])
+        if let count = recordItem?.thumbImgs.count, count > 0, collectionV.cellForItem(at: IndexPath(row: count - 1, section: 0)) != nil {
+            
+            UIView.performWithoutAnimation {
+                collectionV.reloadItems(at: [IndexPath(row: count - 1, section: 0)])
+            }
+            
             let p = CGPoint(x: progress.seconds * 70 / 5.0, y: 0)
             collectionV.contentOffset = p
-        }else {
-            collectionV.reloadData()
+            BFLog(1, message: "px0: \(p.x)")
         }
     }
 }
@@ -78,7 +82,7 @@ extension BFCameraProgressView: UICollectionViewDelegateFlowLayout, UICollection
     func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
         if kind == UICollectionView.elementKindSectionHeader || kind == UICollectionView.elementKindSectionFooter{
             let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: String(describing: UICollectionReusableView.self), for: indexPath)
-            header.backgroundColor = .yellow
+            header.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.3)
             return header
         }
         return UICollectionReusableView()
@@ -90,16 +94,17 @@ extension BFCameraProgressView: UICollectionViewDelegateFlowLayout, UICollection
             if let sticker = recordItem?.videoStickers.first(where: { m in
                 m.thumImgs?.contains(img) ?? false
             }) {
-                if img == sticker.thumImgs!.last {
-                    size = CGSize(width: ((sticker.timelineOut - sticker.timelineIn) * 70.0 / 5.0).truncatingRemainder(dividingBy: 70.0), height: 50)
-                    if (size.width < 0){
-                        BFLog(1, message: "errror")
-                        size = .zero
-                    }
-//                    BFLog(1, message: "currsize \(size), \(indexPath.row), \(sticker.timelineOut), \(sticker.timelineIn)")
-                }else{
-                    size = CGSize(width: 70.0, height: 50)
+                if let (ind, _) = sticker.thumImgs?.enumerated().first(where: { ele in
+                    ele.1 == img
+                }) {
+                    size = CGSize(width: max(0, min((sticker.timelineOut / 5.0  -  CGFloat(ind))*70.0, 70.0)), height: 50.0)
+                }
+                
+                if size.width < 0 {
+                    BFLog(1, message: "ewrr")
                 }
+
+                BFLog(1, message: "curr size - row:\(indexPath.row), \(size.width)")
             }
         }
         return size
@@ -114,10 +119,14 @@ extension BFCameraProgressView: UICollectionViewDelegateFlowLayout, UICollection
             imgview?.contentMode = .scaleAspectFill
             imgview?.tag = 13000
             cell.contentView.addSubview(imgview!)
+            
+            let line = UIView()
+            line.backgroundColor = ThemeStyleColor
+            line.frame = CGRect(x: 0, y: 44, width: 70, height: 6)
         }
         
         imgview?.image = recordItem?.thumbImgs[indexPath.row]
-        
+        BFLog(1, message: "cell manke: \(indexPath.row)")
         return cell
     }
 }
@@ -125,31 +134,30 @@ extension BFCameraProgressView: UICollectionViewDelegateFlowLayout, UICollection
 extension BFCameraProgressView {
     func scrollViewDidScroll(_ scrollView: UIScrollView) {
         if isDrag {
-            let totalW = (scrollView.contentOffset.x + cScreenWidth / 2.0) / scrollView.contentSize.width
-            
-            dragScrollProgressHandle?(false,Float(min(1, max(0, totalW))))
+            dragScrollProgressHandle?(false, scorllToProgress(scrollView))
         }
     }
 
     func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
         isDrag = true
-        let totalW = (scrollView.contentOffset.x + cScreenWidth / 2.0) / scrollView.contentSize.width
         dragStartHandle?()
-        
-        dragScrollProgressHandle?(true,Float(min(1, max(0, totalW))))
+        dragScrollProgressHandle?(true, scorllToProgress(scrollView))
     }
 
     func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
         if !decelerate {
-            let totalW = (scrollView.contentOffset.x + cScreenWidth / 2.0) / scrollView.contentSize.width
             isDrag = false
-            dragEndHandle?(Float(min(1, max(0, totalW))))
+            dragEndHandle?(scorllToProgress(scrollView))
         }
     }
 
     func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
-        let totalW = (scrollView.contentOffset.x + cScreenWidth / 2.0) / scrollView.contentSize.width
         isDrag = false
-        dragEndHandle?(Float(min(1, max(0, totalW))))
+        dragEndHandle?(scorllToProgress(scrollView))
+    }
+    
+    func scorllToProgress(_ scrollView: UIScrollView) -> Float {
+        let totalW = Float(Int(scrollView.contentOffset.x * UIScreen.main.scale)) / Float(Int((scrollView.contentSize.width - cScreenWidth) * UIScreen.main.scale))
+        return Float(min(1, max(0, totalW)))
     }
 }

+ 0 - 12
BFRecordScreenKit/Classes/RecordScreen/View/ProgressView/BFVideoThumbProgressView.swift

@@ -60,18 +60,6 @@ class BFVideoThumbProgressView: BFProgressBaseView {
     override init(frame: CGRect) {
         super.init(frame: frame)
         addSubview(progressView)
-
-        let line = UIView()
-        line.backgroundColor = .white
-        line.layer.borderColor = UIColor.black.cgColor
-        line.layer.borderWidth = 0.3
-        line.layer.cornerRadius = 1.5
-        addSubview(line)
-        line.snp.makeConstraints { make in
-            make.width.equalTo(3)
-            make.center.height.equalToSuperview()
-        }
-
         progressView.contentView.addSubview(progessIndicateBackV)
         progessIndicateBackV.snp.makeConstraints { make in
             make.left.equalTo(width * 0.5)