瀏覽代碼

merge master

wenweiwei 3 年之前
父節點
當前提交
599a874f02
共有 20 個文件被更改,包括 292 次插入91 次删除
  1. 23 0
      BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting+_h.imageset/Contents.json
  2. 二進制
      BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting+_h.imageset/wordSizeSetting+_h.png
  3. 二進制
      BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting+_h.imageset/wordSizeSetting+_h@2x.png
  4. 二進制
      BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting+_h.imageset/wordSizeSetting+_h@3x.png
  5. 23 0
      BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting+_n.imageset/Contents.json
  6. 二進制
      BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting+_n.imageset/wordSizeSetting+_n.png
  7. 二進制
      BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting+_n.imageset/wordSizeSetting+_n@2x.png
  8. 二進制
      BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting+_n.imageset/wordSizeSetting+_n@3x.png
  9. 23 0
      BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting-_h.imageset/Contents.json
  10. 二進制
      BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting-_h.imageset/wordSizeSetting-_h.png
  11. 二進制
      BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting-_h.imageset/wordSizeSetting-_h@2x.png
  12. 二進制
      BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting-_h.imageset/wordSizeSetting-_h@3x.png
  13. 23 0
      BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting-_n.imageset/Contents.json
  14. 二進制
      BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting-_n.imageset/wordSizeSetting-_n.png
  15. 二進制
      BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting-_n.imageset/wordSizeSetting-_n@2x.png
  16. 二進制
      BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting-_n.imageset/wordSizeSetting-_n@3x.png
  17. 11 10
      BFRecordScreenKit/Classes/BFRecordExport.swift
  18. 153 50
      BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift
  19. 6 3
      BFRecordScreenKit/Classes/RecordScreen/View/BFSubtitleEditView.swift
  20. 30 28
      BFRecordScreenKit/Classes/RecordScreen/View/BFSubtitleSettingView.swift

+ 23 - 0
BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting+_h.imageset/Contents.json

@@ -0,0 +1,23 @@
+{
+  "images" : [
+    {
+      "filename" : "wordSizeSetting+_h.png",
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "filename" : "wordSizeSetting+_h@2x.png",
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "filename" : "wordSizeSetting+_h@3x.png",
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

二進制
BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting+_h.imageset/wordSizeSetting+_h.png


二進制
BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting+_h.imageset/wordSizeSetting+_h@2x.png


二進制
BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting+_h.imageset/wordSizeSetting+_h@3x.png


+ 23 - 0
BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting+_n.imageset/Contents.json

@@ -0,0 +1,23 @@
+{
+  "images" : [
+    {
+      "filename" : "wordSizeSetting+_n.png",
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "filename" : "wordSizeSetting+_n@2x.png",
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "filename" : "wordSizeSetting+_n@3x.png",
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

二進制
BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting+_n.imageset/wordSizeSetting+_n.png


二進制
BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting+_n.imageset/wordSizeSetting+_n@2x.png


二進制
BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting+_n.imageset/wordSizeSetting+_n@3x.png


+ 23 - 0
BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting-_h.imageset/Contents.json

@@ -0,0 +1,23 @@
+{
+  "images" : [
+    {
+      "filename" : "wordSizeSetting-_h.png",
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "filename" : "wordSizeSetting-_h@2x.png",
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "filename" : "wordSizeSetting-_h@3x.png",
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

二進制
BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting-_h.imageset/wordSizeSetting-_h.png


二進制
BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting-_h.imageset/wordSizeSetting-_h@2x.png


二進制
BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting-_h.imageset/wordSizeSetting-_h@3x.png


+ 23 - 0
BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting-_n.imageset/Contents.json

@@ -0,0 +1,23 @@
+{
+  "images" : [
+    {
+      "filename" : "wordSizeSetting-_n.png",
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "filename" : "wordSizeSetting-_n@2x.png",
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "filename" : "wordSizeSetting-_n@3x.png",
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

二進制
BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting-_n.imageset/wordSizeSetting-_n.png


二進制
BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting-_n.imageset/wordSizeSetting-_n@2x.png


二進制
BFRecordScreenKit/Assets/BFRecordScreenKit.xcassets/wordSizeSetting-_n.imageset/wordSizeSetting-_n@3x.png


+ 11 - 10
BFRecordScreenKit/Classes/BFRecordExport.swift

@@ -188,16 +188,17 @@ public class BFRecordExport {
         if voiceCount > 0 || videoStickers.count > 1 {
             let (audioMix, composition) = mergeAudio(videoStickers: videoStickers, audios: voiceList, synthesisAll: synthesisAll)
 
-            let filter = videoStickers.map { sticker in
-                PQMovieFilter(movieSticker: sticker)
+            var filters:[PQBaseFilter] =  Array.init()
+            for sticker in videoStickers {
+                filters.append(PQMovieFilter(movieSticker: sticker))
             }
-
-            exporter = PQCompositionExporter(asset: composition, videoComposition: nil, audioMix: audioMix, filters: filter, animationTool: nil, exportURL: outPutMP4URL)
-
-//            let asset = data?.first?.baseMaterial // 可能为空
-
-            let size = UIScreen.main.bounds.size // getVideoSize(asset: asset!)
-            var orgeBitRate = Int(size.width * size.height * 3)
+            let outputSize:CGSize = CGSize(width: 1080.0, height: 1080 * CGFloat(Int(UIScreen.main.bounds.size.height / UIScreen.main.bounds.size.width)))
+            BFLog(message: "输出视频大小:\(outputSize)")
+            filters.append(PQSubTitleFilter.init(st: titleStickers, inputSize: outputSize))
+            
+            exporter = PQCompositionExporter(asset: composition, videoComposition: nil, audioMix: audioMix, filters: filters, animationTool: nil, exportURL: outPutMP4URL)
+ 
+            var orgeBitRate = Int(outputSize.width * outputSize.height * 3)
 
             for stick in videoStickers {
                 if stick.type == StickerType.VIDEO.rawValue {
@@ -212,7 +213,7 @@ public class BFRecordExport {
 
             BFLog(message: "导出设置的码率为:\(orgeBitRate)")
 
-            if exporter!.prepare(videoSize: size, videoAverageBitRate: orgeBitRate) {
+            if exporter!.prepare(videoSize: outputSize, videoAverageBitRate: orgeBitRate) {
                 exporter!.start(playeTimeRange: CMTimeRange(start: CMTime.zero, end: synthesisAll ? CMTime(seconds: totalDuration, preferredTimescale: 100) : composition.duration))
             }
             exporter?.progressClosure = { [weak self] _, _, progress in

+ 153 - 50
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -15,8 +15,9 @@ import Photos
 import UIKit
 
 struct WithDrawModel {
-    var type: Int // 0:拖动; 1:预览播放暂停 2: 录音结束
+    var type: Int // 0:拖动; 1:预览播放暂停 2: 录音结束  3: 删除录音
     var timestamp: Double
+    var deletedVoices : [(PQVoiceModel, Int)]?
 }
 
 public class BFRecordScreenController: BFBaseViewController {
@@ -30,6 +31,7 @@ public class BFRecordScreenController: BFBaseViewController {
 
     var currItemModelIndex = 0
     public var itemModels = [BFRecordItemModel]()
+    var showSubtitleIndex = 0
     //    var shouldPlayRecordIndex:Int = -1          // 当前应该播放的录音资源序号
     var currentPlayRecordIndex: Int = -1 // >= 0 :当前正在播放的录音资源序号; -3: 刚录音完,不需要播放录音; -1:初始化阶段
     var isRecording = false { // 是否正在录音
@@ -38,6 +40,7 @@ public class BFRecordScreenController: BFBaseViewController {
             changeVoiceBtn.isHidden = isRecording
             recordBtn.setTitle(isRecording ? "松手 完成" : "按住 说话", for: .normal)
             recordBtn.backgroundColor = UIColor.hexColor(hexadecimal: "#28BE67", alpha: isRecording ? 0.6 : 1)
+            playBtn.isSelected = isRecording
         }
     }
 
@@ -88,16 +91,33 @@ public class BFRecordScreenController: BFBaseViewController {
             if let sself = self, let model = model, FileManager.default.fileExists(atPath: model.wavFilePath ?? "") {
                 // 加入到语音数组里
                 // TODO: 原逻辑要删除新录音后边的数据, 新逻辑是覆盖则删除
+                model.endTime = sself.currentAssetProgress.seconds
+
+                let newRange = CMTimeRange(start: CMTime(seconds: model.startTime, preferredTimescale: 1000), end: CMTime(seconds: model.endTime, preferredTimescale: 1000))
+
+                var deletedVoices = [(PQVoiceModel, Int)]()
+                
                 for (i, m) in sself.itemModels[sself.currItemModelIndex].voiceStickers.enumerated() {
-                    if model.endTime > m.startTime && model.endTime <= m.endTime
-                        || model.startTime <= m.startTime && model.startTime > m.endTime
-                    {
-                        sself.itemModels[sself.currItemModelIndex].voiceStickers.remove(at: i)
+                    let originRange = CMTimeRange(start: CMTime(seconds: m.startTime, preferredTimescale: 1000), end: CMTime(seconds: m.endTime, preferredTimescale: 1000))
+                    
+                    if CMTimeRangeGetIntersection(originRange, otherRange: newRange).duration.seconds > 0{
+                        deletedVoices.append((m, i))
                         continue
                     }
                 }
+                sself.itemModels[sself.currItemModelIndex].voiceStickers.removeAll { m in
+                    let originRange = CMTimeRange(start: CMTime(seconds: m.startTime, preferredTimescale: 1000), end: CMTime(seconds: m.endTime, preferredTimescale: 1000))
+                    return CMTimeRangeGetIntersection(originRange, otherRange: newRange).duration.seconds > 0
+                }
                 BFLog(1, message: "添加录音文件:\(model.startTime) -- \(model.endTime)")
-
+                sself.withDrawBtn.setTitle("撤销录制", for: .normal)
+                var event = sself.events.last
+                if event != nil {
+                    event!.deletedVoices = deletedVoices
+                    sself.events.removeLast()
+                    sself.events.append(event!)
+                }
+                
                 sself.itemModels[sself.currItemModelIndex].voiceStickers.append(model)
 
                 sself.drawOrUpdateRecordProgessLable()
@@ -158,6 +178,16 @@ public class BFRecordScreenController: BFBaseViewController {
 
         return btn
     }()
+    lazy var deleteRecordBtn: UIButton = {
+        let btn = UIButton(type: .custom)
+        btn.backgroundColor = .red
+        btn.alpha = 0.5
+        btn.setTitle("删除录制", for: .normal)
+        btn.adjustsImageWhenHighlighted = false
+        btn.addTarget(self, action: #selector(deleteRecorded), for: .touchUpInside)
+        btn.isHidden = true
+        return btn
+    }()
 
     lazy var withDrawBtn: UIButton = {
         let btn = UIButton(type: .custom)
@@ -257,16 +287,10 @@ public class BFRecordScreenController: BFBaseViewController {
 
     // 显示字幕
     lazy var subtitleLabel: PQSubTitleLabel = {
-        let test = ""
-        let leftPoint: CGFloat = 37
-        let height = sizeWithText(text: test, font: UIFont.boldSystemFont(ofSize: 70 * 375 / 1080), size: CGSize(width: cScreenWidth - leftPoint * 2, height: 102))
-
-        let subtitleLabel = PQSubTitleLabel(frame: CGRect(x: leftPoint, y: cScreenHeigth * 0.70 - height.height, width: cScreenWidth - 37 * 2, height: height.height))
+        let subtitleLabel = PQSubTitleLabel()
         subtitleLabel.textAlignment = .center
-        subtitleLabel.text = test
-
         subtitleLabel.numberOfLines = 0
-        subtitleLabel.lineBreakMode = .byClipping
+        subtitleLabel.lineBreakMode = .byWordWrapping
         subtitleLabel.isUserInteractionEnabled = true
         subtitleLabel.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(editSubtitle)))
         return subtitleLabel
@@ -392,6 +416,7 @@ public class BFRecordScreenController: BFBaseViewController {
         bottomeView.addSubview(progreddL)
         //        view.addSubview(toolV)
         bottomeView.addSubview(recordBtn)
+        bottomeView.addSubview(deleteRecordBtn)
         bottomeView.addSubview(withDrawBtn)
         //        bottomeView.addSubview(changeVoiceBtn)
         bottomeView.addSubview(progressThumV)
@@ -416,9 +441,16 @@ public class BFRecordScreenController: BFBaseViewController {
 
             self?.setSubtitleStyle(settingModel: subtitileModel.setting)
         }
-        subtitleEditView.editSubtitleDone = { [weak self] newtext in
+        subtitleEditView.editSubtitleDone = { [weak self] newtext ,index in
+            //1,刷新 UI
             self?.subtitleLabel.text = newtext
-        }
+            
+            self?.setSubtitleStyle(settingModel: (self?.subtitleSettingView.subtitle.setting)!)
+            
+            //更新缓存数据
+            if(index < (self?.itemModels[(self?.currItemModelIndex ?? 0)].titleStickers.count ?? 0)){
+                self?.itemModels[self?.currItemModelIndex ?? 0].titleStickers[index].text = newtext}
+            }
 
         layoutsubview()
 
@@ -426,25 +458,30 @@ public class BFRecordScreenController: BFBaseViewController {
     }
 
     @objc func editSubtitle() {
-        BFLog(message: "编辑字幕")
+        BFLog(message: "编辑字幕 index:\(showSubtitleIndex)")
         subtitleEditView.isHidden = false
         subtitleEditView.textView.becomeFirstResponder()
-        subtitleEditView.setNewText(text: subtitleLabel.text ?? "")
+        subtitleEditView.setNewText(text: subtitleLabel.text ?? "",index: showSubtitleIndex)
     }
 
     /// 更新字幕,在回放时使用
     /// - Parameter time: 当前播放的进度
     func updateSubtitle(time: CMTime) {
         var findShowSubtitle: PQEditSubTitleModel?
-        for subtitle in itemModels[currItemModelIndex].titleStickers {
-            if subtitle.timelineIn <= CMTimeGetSeconds(time) * 1_000_000, subtitle.timelineOut >= CMTimeGetSeconds(time) * 1_000_000 {
+        for (index,subtitle) in itemModels[currItemModelIndex].titleStickers.enumerated() {
+            if subtitle.timelineIn <= CMTimeGetSeconds(time)  , subtitle.timelineOut >= CMTimeGetSeconds(time)  {
                 findShowSubtitle = subtitle
                 BFLog(message: "找到要显示的字幕 in \(findShowSubtitle?.timelineIn ?? 0.0) out \(findShowSubtitle?.timelineOut ?? 0.0) text:\(findShowSubtitle?.text ?? "") currTime is \(CMTimeGetSeconds(time))")
+                showSubtitleIndex = index
                 break
             }
         }
         if findShowSubtitle != nil {
             subtitleLabel.text = findShowSubtitle?.text
+            setSubtitleStyle(settingModel: subtitleSettingView.subtitle.setting)
+            
+        }else{
+            subtitleLabel.text = ""
         }
     }
 
@@ -459,15 +496,17 @@ public class BFRecordScreenController: BFBaseViewController {
             subtitleLabel.textColor = settingModel.fontColor
 
             let leftPoint: CGFloat = 37
-            let height = sizeWithText(text: subtitleLabel.text ?? "", font: UIFont.systemFont(ofSize: CGFloat(settingModel.subtitleSize * 375 / 1080)), size: CGSize(width: cScreenWidth - leftPoint * 2, height: 102))
-
+            
+            
+            let height = sizeTextFits(attributedText: nil, text: subtitleLabel.text ?? "", numberOfLines: 0, font:   subtitleLabel.font, maxSize: CGSize(width:  cScreenWidth - leftPoint * 2, height: CGFloat.greatestFiniteMagnitude)).height
+     
             // 下 //设置位置
             if subtitleSettingView.subtitle.setting.subtitlePoint == 0 {
-                subtitleLabel.frame = CGRect(x: leftPoint, y: cScreenHeigth * 0.70 - height.height, width: cScreenWidth - 37 * 2, height: height.height)
+                subtitleLabel.frame = CGRect(x: leftPoint, y: cScreenHeigth * 0.70 - height, width: cScreenWidth - 37 * 2, height: height)
             } else if subtitleSettingView.subtitle.setting.subtitlePoint == 1 { // 中
-                subtitleLabel.frame = CGRect(x: leftPoint, y: cScreenHeigth / 2.0 - height.height / 2.0, width: cScreenWidth - 37 * 2, height: height.height)
+                subtitleLabel.frame = CGRect(x: leftPoint, y: cScreenHeigth / 2.0 - height / 2.0, width: cScreenWidth - 37 * 2, height: height)
             } else { // 上
-                subtitleLabel.frame = CGRect(x: leftPoint, y: cScreenHeigth * 0.12, width: cScreenWidth - 37 * 2, height: height.height)
+                subtitleLabel.frame = CGRect(x: leftPoint, y: cScreenHeigth * 0.12, width: cScreenWidth - 37 * 2, height: height)
             }
         }
     }
@@ -501,6 +540,12 @@ public class BFRecordScreenController: BFBaseViewController {
             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)
@@ -610,16 +655,34 @@ public class BFRecordScreenController: BFBaseViewController {
 
         audioSettingView.isHidden = false
     }
+    
+    
+    @objc func deleteRecorded(){
+        if isStopAtRecordRange != -1, isStopAtRecordRange < itemModels[currItemModelIndex].voiceStickers.count {
+            let model = itemModels[currItemModelIndex].voiceStickers[isStopAtRecordRange]
+            itemModels[currItemModelIndex].voiceStickers.remove(at: isStopAtRecordRange)
+            drawOrUpdateRecordProgessLable()
+            searchStopAtRecordRange()
+            events.append(WithDrawModel(type: 3, timestamp: self.currentAssetProgress.seconds, deletedVoices: [(model, isStopAtRecordRange)]))
+        }
+    }
 
     @objc func startRecord() {
         BFLog(1, message: "start \(UIControl.Event.touchDown)")
 
+        // 停止进度条滚动
         let point = progressThumV.progressView.contentOffset
         progressThumV.progressView.setContentOffset(point, animated: false)
 
-        isRecording = true
         pause()
+        isRecording = true
 
+        let model = PQVoiceModel()
+        model.startTime = currentAssetProgress.seconds
+        model.volume = 100
+        recorderManager.voiceModel = model
+        recorderManager.startRecord(index: 1)
+        
         movie?.startProcessing()
         assetPlayer?.volume = 0
         assetPlayer?.play()
@@ -629,11 +692,7 @@ public class BFRecordScreenController: BFBaseViewController {
             avatarView.beginRecord()
         }
 
-        let model = PQVoiceModel()
-        model.startTime = currentAssetProgress.seconds
-        model.volume = 100
-        recorderManager.voiceModel = model
-        recorderManager.startRecord(index: 1)
+        
 
         // 添加撤销记录点
         events.append(WithDrawModel(type: 2, timestamp: model.startTime))
@@ -657,14 +716,13 @@ public class BFRecordScreenController: BFBaseViewController {
         DispatchQueue.global().async {
             self.speechTranscriberUtil?.endTranscriber()
         }
-        playBtn.isSelected = true
+//        playBtn.isSelected = true
         // 存储录音
         isRecording = false
+        pause()
 
-        recorderManager.voiceModel?.endTime = currentAssetProgress.seconds
         recorderManager.endRecord()
 
-        pause()
         if !avatarView.isHidden {
             avatarView.endRecord()
         }
@@ -688,10 +746,35 @@ public class BFRecordScreenController: BFBaseViewController {
                 }) {
                     let model = itemModels[currItemModelIndex].voiceStickers[modelIndex]
                     itemModels[currItemModelIndex].voiceStickers.remove(at: modelIndex)
+                    
+                    var tuples = action.deletedVoices
+                    if tuples != nil, tuples!.count > 0 {
+                        tuples!.sort { tuple1, tuple2 in
+                            tuple1.1 < tuple2.1
+                        }
+                        tuples?.forEach({ tuple in
+                            itemModels[currItemModelIndex].voiceStickers.insert(tuple.0, at: tuple.1)
+                        })
+                    }
+                    
                     drawOrUpdateRecordProgessLable()
                     jumpTime = model.startTime
                 }
-            } else {}
+            } else if action.type == 3 {
+                // 删除录音
+                var tuples = action.deletedVoices
+                if tuples != nil, tuples!.count > 0 {
+                    tuples!.sort { tuple1, tuple2 in
+                        tuple1.1 < tuple2.1
+                    }
+                    tuples?.forEach({ tuple in
+                        itemModels[currItemModelIndex].voiceStickers.insert(tuple.0, at: tuple.1)
+                    })
+                }
+                drawOrUpdateRecordProgessLable()
+            } else {
+                
+            }
             events.removeLast()
             let dur = itemModels[currItemModelIndex].materialDuraion
             if dur > 0 {
@@ -701,6 +784,13 @@ public class BFRecordScreenController: BFBaseViewController {
                 hadPrepareToPlayRecord = false
                 progressThumV.progress = jumpTime
             }
+            
+            if let event = events.last,  event.type == 2{
+                withDrawBtn.setTitle("撤销录制", for: .normal)
+            }else{
+                withDrawBtn.setTitle("撤销", for: .normal)
+            }
+            searchStopAtRecordRange()
         }
     }
 
@@ -715,6 +805,7 @@ public class BFRecordScreenController: BFBaseViewController {
             searchStopAtRecordRange()
         } else {
             events.append(WithDrawModel(type: 1, timestamp: currentAssetProgress.seconds))
+            withDrawBtn.setTitle("撤销", for: .normal)
             play()
         }
     }
@@ -742,10 +833,12 @@ public class BFRecordScreenController: BFBaseViewController {
         hadPrepareToPlayRecord = false
         BFLog(1, message: isDragingProgressSlder ? "drag false" : "drag  tr")
         searchStopAtRecordRange()
+        withDrawBtn.setTitle("撤销", for: .normal)
+
     }
 
     func searchStopAtRecordRange() {
-        // TODO: 判断是否停止录音区间,是则删除相关录音,画笔,头像,字幕
+        // TODO: 滑动,播放暂停,撤销时,判断是否停止录音区间,是则删除相关录音,画笔,头像,字幕
         let elems = itemModels[currItemModelIndex].voiceStickers.enumerated().filter { elem in
             elem.1.startTime <= self.currentAssetProgress.seconds && elem.1.endTime > self.currentAssetProgress.seconds
         }
@@ -753,11 +846,17 @@ public class BFRecordScreenController: BFBaseViewController {
 
         if elems.count > 0 {
             //  TODO: 停在了录音区间,显示删除按钮
+            deleteRecordBtn.isHidden = false
+            recordBtn.isHidden = true
+            
             isStopAtRecordRange = elems.first!.0
-            BFLog(1, message: "停在了录音区间 里")
+            BFLog(1, message: "停在了录音区间里 \(isStopAtRecordRange)")
         } else {
+            deleteRecordBtn.isHidden = true
+            recordBtn.isHidden = false
+            
             isStopAtRecordRange = -1
-            BFLog(1, message: "停在了录音区间 外")
+            BFLog(1, message: "停在了录音区间外 \(isStopAtRecordRange)")
         }
     }
 
@@ -980,10 +1079,9 @@ public class BFRecordScreenController: BFBaseViewController {
             assetPlayer?.volume = 0
             avplayerTimeObserver = assetPlayer?.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 100), queue: DispatchQueue.global()) { [weak self] time in
                 //    进度监控
-
-                self?.currentAssetProgress = time
-                BFLog(1, message: "curr:\(CMTimeGetSeconds(time))")
-                if CMTimeGetSeconds(item?.duration ?? CMTime.zero) > 0 {
+               self?.currentAssetProgress = CMTime(seconds: time.seconds, preferredTimescale: 1000)
+                BFLog(1, message: "curr:\(CMTimeGetSeconds(self?.currentAssetProgress ?? .zero))")
+                if CMTimeGetSeconds(item.duration) > 0 {
                     DispatchQueue.main.async { [weak self] in
                         self?.progreddL.text = String(format: "%@", CMTimeGetSeconds(time).formatDurationToHMS())
                         let su = !(self?.isDragingProgressSlder ?? false) || (self?.isRecording ?? false && self?.isNormalPlaying ?? false)
@@ -1032,12 +1130,12 @@ public class BFRecordScreenController: BFBaseViewController {
 
     func changeProgress(progress: Float) {
         if let duration = assetPlayer?.currentItem?.duration {
-            currentAssetProgress = CMTime(value: CMTimeValue(progress * Float(CMTimeGetSeconds(duration)) * 100), timescale: 100)
+            currentAssetProgress = CMTime(value: CMTimeValue(progress * Float(CMTimeGetSeconds(duration)) * 1000), timescale: 1000)
             DispatchQueue.main.async { [weak self] in
                 self!.progreddL.text = String(format: "%@", CMTimeGetSeconds(self!.currentAssetProgress).formatDurationToHMS())
             }
 
-            assetPlayer!.seek(to: currentAssetProgress, toleranceBefore: CMTime(value: 1, timescale: 1_000_000), toleranceAfter: CMTime(value: 1, timescale: 1_000_000)) { _ in
+            assetPlayer!.seek(to: currentAssetProgress, toleranceBefore: CMTime(value: 1, timescale: 1000), toleranceAfter: CMTime(value: 1, timescale: 1000)) { _ in
             }
         }
     }
@@ -1094,16 +1192,21 @@ extension BFRecordScreenController: PQSpeechTranscriberUtilDelegate {
 
         BFLog(message: "识别结果:dicResult is \(String(describing: dicResult)) \((payload?["result"])!)")
         DispatchQueue.main.async {
-            // 1,显示字幕
-//            self.subtitleLabel.text = ((payload?["result"]) as? String) ?? ""
-            self.setSubtitleStyle(settingModel: self.subtitleSettingView.subtitle.setting)
-
+       
             // 2,保存字幕数据
             let newSubtitle = PQEditSubTitleModel()
             newSubtitle.timelineIn = self.itemModels[self.currItemModelIndex].titleStickers.last?.timelineOut ?? 0
             // 当前已处理的音频时长,单位:毫秒。
-            newSubtitle.timelineOut = Float64(((payload?["time"]) as? Int) ?? 0) * 1_000_000
-            newSubtitle.text = ((payload?["result"]) as? String) ?? ""
+             
+            newSubtitle.timelineOut = Float64(((payload?["time"]) as? Int) ?? 0) / 1_000.0 + (self.recorderManager.voiceModel?.startTime ?? 0.0)
+            var showText = ((payload?["result"]) as? String) ?? ""
+            if(showText.count > 30){
+                showText = showText.substring(to: 30)
+                showText += "..."
+            }
+            newSubtitle.text = showText
+            
+            BFLog(message: "添加字幕数据 timelineIn \(newSubtitle.timelineIn) timelineOut \(newSubtitle.timelineOut) text \(newSubtitle.text)")
             newSubtitle.setting = self.subtitleSettingView.subtitle.setting
 
             self.itemModels[self.currItemModelIndex].titleStickers.append(newSubtitle)

+ 6 - 3
BFRecordScreenKit/Classes/RecordScreen/View/BFSubtitleEditView.swift

@@ -10,9 +10,11 @@ import BFMediaKit
 import BFUIKit
 import Foundation
 
-typealias EditSubtitleDone = (_ text: String) -> Void
+typealias EditSubtitleDone = (_ text: String,_ index:Int) -> Void
 
 class BFSubtitleEditView: UIView {
+    
+    var showSubtitleIndex = 0
     var editSubtitleDone: EditSubtitleDone?
 
 //    var settingModel:BFSubtitileSettingModel = BFSubtitileSettingModel.init()
@@ -91,11 +93,12 @@ class BFSubtitleEditView: UIView {
         textView.resignFirstResponder()
         if editSubtitleDone != nil {
             BFLog(message: "最后修改的文字为:\(String(describing: textView.text))")
-            editSubtitleDone!(textView.text)
+            editSubtitleDone!(textView.text,showSubtitleIndex)
         }
     }
 
-    func setNewText(text: String) {
+    func setNewText(text: String,index:Int) {
+        showSubtitleIndex = index
         textView.text = text.substring(to: 30)
 //        BFLog(message: "传值\(textView.text)")
 //

+ 30 - 28
BFRecordScreenKit/Classes/RecordScreen/View/BFSubtitleSettingView.swift

@@ -37,8 +37,9 @@ class BFSubtitleSettingView: UIView {
         backgroundColor = UIColor.clear
         addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(hidden)))
 
-        let backView = UIView(frame: CGRect(x: 0, y: 0, width: cScreenWidth, height: cScreenHeigth))
+        let backView = UIButton()
         backView.backgroundColor = .black
+
         addSubview(backView)
         backView.snp.makeConstraints { make in
             make.right.equalTo(self.snp.right)
@@ -136,22 +137,14 @@ class BFSubtitleSettingView: UIView {
         for i in 0...1 {
             let wordSizeBtn = UIButton(type: .custom)
             wordSizeBtn.addTarget(self, action: #selector(wordSizeSetting(sender:)), for: .touchUpInside)
-            wordSizeBtn.backgroundColor = UIColor.hexColor(hexadecimal: "#1A1A1A")
-            wordSizeBtn.setTitleColor(UIColor.hexColor(hexadecimal: "#28BE67"), for: .selected)
-            wordSizeBtn.setTitleColor(.white, for: .normal)
-            wordSizeBtn.setTitle(i == 0 ? "-" : "+", for: .normal)
             backView.addSubview(wordSizeBtn)
             wordSizeBtn.tag = i
-            if i == 0 {
-                wordSizeBtn.isSelected = true
-                wordSizeBtn.layer.borderColor = UIColor.hexColor(hexadecimal: "#28BE67").cgColor
-                wordSizeBtn.layer.borderWidth = 1.5
-                lastSelectwordSizeBtn = wordSizeBtn
-            }
-            wordSizeBtn.addCorner(corner: 10)
+            
+            wordSizeBtn.setBackgroundImage(imageInRecordScreenKit(by: i == 0 ? "wordSizeSetting-_h" : "wordSizeSetting+_h"), for: .normal)
+ 
             wordSizeBtn.snp.makeConstraints { make in
-                make.width.equalTo(30)
-                make.height.equalTo(30)
+                make.width.equalTo(24)
+                make.height.equalTo(24)
                 make.left.equalTo(wordSizeTitle.snp.right).offset(10 + i * Int(30 + 10))
 
                 make.centerY.equalTo(pointTitle.snp.centerY)
@@ -245,22 +238,31 @@ class BFSubtitleSettingView: UIView {
     }
 
     @objc func wordSizeSetting(sender: UIButton) {
-        lastSelectwordSizeBtn.isSelected = false
-        lastSelectwordSizeBtn.layer.borderColor = UIColor.clear.cgColor
-
-        sender.isSelected = true
+        
+        if(sender.tag == 0){
+            if(subtitle.setting.subtitleSize > 20){
+                subtitle.setting.subtitleSize -= 10
+                
+                lastSelectwordSizeBtn.setImage(imageInRecordScreenKit(by:  "wordSizeSetting+_h"), for: .normal)
+                
+                sender.setImage(imageInRecordScreenKit(by:  "wordSizeSetting-_h"), for: .normal)
+            }else{
+                sender.setImage(imageInRecordScreenKit(by:  "wordSizeSetting-_n"), for: .normal)
+            }
+            
+        }else  if(sender.tag == 1){
+            if(subtitle.setting.subtitleSize < 120){
+                subtitle.setting.subtitleSize += 10
+                sender.setImage(imageInRecordScreenKit(by:  "wordSizeSetting+_h"), for: .normal)
+                lastSelectwordSizeBtn.setImage(imageInRecordScreenKit(by:  "wordSizeSetting-_h"), for: .normal)
+            }else{
+                sender.setImage(imageInRecordScreenKit(by:  "wordSizeSetting+_n"), for: .normal)
+            }
+            
+        }
+ 
         lastSelectwordSizeBtn = sender
 
-        sender.layer.borderColor = UIColor.hexColor(hexadecimal: "#28BE67").cgColor
-        sender.layer.borderWidth = 1.5
-
-        if sender.tag == 0, subtitle.setting.subtitleSize > 20 {
-            subtitle.setting.subtitleSize -= 10
-        } else if sender.tag == 1, subtitle.setting.subtitleSize < 120 {
-            subtitle.setting.subtitleSize += 10
-        } else {
-            BFLog(message: "设置字号超出范围!")
-        }
         if subtitleSettingCallBack != nil {
             subtitleSettingCallBack!(subtitle)
         }