Explorar o código

Merge branch 'master' of https://git.yishihui.com/iOS/BFRecordScreenKit

wenweiwei %!s(int64=3) %!d(string=hai) anos
pai
achega
9f90f79f98

+ 39 - 3
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -15,9 +15,11 @@ import Photos
 import UIKit
 
 struct WithDrawModel {
-    var type: Int // 0:拖动; 1:预览播放暂停 2: 录音结束  3: 删除录音
+    var type: Int // 0:拖动; 1:预览播放暂停 2: 录音结束  3: 删除录音  4: 删除字幕
     var timestamp: Double
     var deletedVoices: [(PQVoiceModel, Int)]?
+    // add by ak 保存删除的字幕数据用于恢复
+    var deletedTittles:[(PQEditSubTitleModel,Int)]?
 }
 
 public class BFRecordScreenController: BFBaseViewController {
@@ -30,6 +32,7 @@ public class BFRecordScreenController: BFBaseViewController {
     public var assets = [PHAsset]()
     var currItemModelIndex = 0
     public var itemModels = [BFRecordItemModel]()
+    //add by ak 当前的显示的字幕位置
     var showSubtitleIndex = 0
     //    var shouldPlayRecordIndex:Int = -1          // 当前应该播放的录音资源序号
     var currentPlayRecordIndex: Int = -1 // >= 0 :当前正在播放的录音资源序号; -3: 刚录音完,不需要播放录音; -1:初始化阶段
@@ -677,6 +680,34 @@ public class BFRecordScreenController: BFBaseViewController {
 
         audioSettingView.isHidden = false
     }
+ 
+    /// 删除指定段落的所有字幕 数据
+    /// - Parameter voiceModel: 删除的音频数据
+    func deleteTitles(voiceModel:PQVoiceModel){
+          BFLog(message: "itemModels[currItemModelIndex].titleStickers  删除前:\(itemModels[currItemModelIndex].titleStickers.count) model.startTime: \(voiceModel.startTime) model.end: \(voiceModel.endTime)")
+          for title in itemModels[currItemModelIndex].titleStickers {
+              if let index = itemModels[currItemModelIndex].titleStickers.firstIndex(of: title) {
+                  
+                  if title.timelineIn >= voiceModel.startTime && title.timelineOut <= voiceModel.endTime{
+                    
+                      //删除前数据存入缓存
+                      let sutbitle  = itemModels[currItemModelIndex].titleStickers[index]
+                      events.append(WithDrawModel(type: 4, timestamp: currentAssetProgress.seconds, deletedTittles: [(sutbitle,isStopAtRecordRange)]))
+                      
+                      itemModels[currItemModelIndex].titleStickers.remove(at: index)
+                      
+                  
+ 
+                  }
+         
+              }
+          }
+         BFLog(message: "itemModels[currItemModelIndex].titleStickers  删除后:\(itemModels[currItemModelIndex].titleStickers.count)")
+ 
+          //清空字幕UI
+         subtitleLabel.text = ""
+        
+    }
 
     @objc func deleteRecorded() {
         if isStopAtRecordRange != -1, isStopAtRecordRange < itemModels[currItemModelIndex].voiceStickers.count {
@@ -685,6 +716,9 @@ public class BFRecordScreenController: BFBaseViewController {
             drawOrUpdateRecordProgessLable()
             searchStopAtRecordRange()
             events.append(WithDrawModel(type: 3, timestamp: currentAssetProgress.seconds, deletedVoices: [(model, isStopAtRecordRange)]))
+     
+            deleteTitles(voiceModel: model)
+            
         }
     }
 
@@ -761,6 +795,7 @@ public class BFRecordScreenController: BFBaseViewController {
     @objc func withdrawAction() {
         pause()
         if let action = events.last {
+ 
             var jumpTime = action.timestamp
             if action.type == 2 {
                 // 撤销录制
@@ -862,6 +897,7 @@ public class BFRecordScreenController: BFBaseViewController {
         let elems = itemModels[currItemModelIndex].voiceStickers.enumerated().filter { elem in
             elem.1.startTime <= self.currentAssetProgress.seconds && elem.1.endTime > self.currentAssetProgress.seconds
         }
+        
         isEndPlay = false
 
         if elems.count > 0 {
@@ -1269,8 +1305,8 @@ extension BFRecordScreenController: PQSpeechTranscriberUtilDelegate {
 
             newSubtitle.timelineOut = Float64(((payload?["time"]) as? Int) ?? 0) / 1000.0 + (self.recorderManager.voiceModel?.startTime ?? 0.0)
             var showText = ((payload?["result"]) as? String) ?? ""
-            if showText.count > 30 {
-                showText = showText.substring(to: 30)
+            if showText.count > subtitleMaxlength {
+                showText = showText.substring(to: subtitleMaxlength)
                 showText += "..."
             }
             newSubtitle.text = showText

+ 2 - 0
BFRecordScreenKit/Classes/RecordScreen/View/BFAudioSettingView.swift

@@ -40,6 +40,7 @@ class BFAudioSettingView: UIView {
         haveSpeakSlider.maximumTrackTintColor = UIColor.hexColor(hexadecimal: "#E6E8E8")
         haveSpeakSlider.minimumTrackTintColor = UIColor.hexColor(hexadecimal: BFConfig.shared.styleColor.rawValue)
         haveSpeakSlider.tag = 10
+        haveSpeakSlider.unit = "%"
 //        speechSlidView.addTarget(self, action: #selector(sliderTouchEnded(sender:)), for: .touchUpInside)
         haveSpeakSlider.maximumValue = 100
         haveSpeakSlider.minimumValue = 0
@@ -74,6 +75,7 @@ class BFAudioSettingView: UIView {
 //        speechSlidView.addTarget(self, action: #selector(sliderTouchEnded(sender:)), for: .touchUpInside)
         noSpeakSlider.maximumValue = 100
         noSpeakSlider.minimumValue = 0
+        noSpeakSlider.unit = "%"
         noSpeakSlider.valueTextColor = UIColor.hexColor(hexadecimal: BFConfig.shared.styleColor.rawValue)
         noSpeakSlider.value = 100
 

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

@@ -12,6 +12,10 @@ import Foundation
 
 typealias EditSubtitleDone = (_ text: String,_ index:Int) -> Void
 
+
+//字幕最大数限制
+public let subtitleMaxlength:Int = 30
+
 class BFSubtitleEditView: UIView {
     
     var showSubtitleIndex = 0
@@ -21,7 +25,7 @@ class BFSubtitleEditView: UIView {
     /// 输入框
     lazy var textView: BFTextView = {
         let textView = BFTextView()
-        textView.maxTextLength = 30
+        textView.maxTextLength = subtitleMaxlength
         textView.maxTextLengthRemind = ""
         textView.backgroundColor = UIColor.clear
         textView.textColor = UIColor.hexColor(hexadecimal: "#FFFFFF")
@@ -99,7 +103,7 @@ class BFSubtitleEditView: UIView {
 
     func setNewText(text: String,index:Int) {
         showSubtitleIndex = index
-        textView.text = text.substring(to: 30)
+        textView.text = text.substring(to: subtitleMaxlength)
 //        BFLog(message: "传值\(textView.text)")
 //
 //        let attributedText = NSMutableAttributedString(string: textView.text,attributes: [.font: UIFont.systemFont(ofSize: CGFloat(settingModel.subtitleSize)  * 375 / 1080),.strokeWidth:-6,.strokeColor: settingModel.strokeColor,.foregroundColor:settingModel.fontColor])