Kaynağa Gözat

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

wenweiwei 3 yıl önce
ebeveyn
işleme
7d672add2d

+ 38 - 26
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -22,7 +22,7 @@ struct WithDrawModel {
     var timestamp: Double
     var timestamp: Double
     var deletedVoices: [(PQVoiceModel, Int)]?
     var deletedVoices: [(PQVoiceModel, Int)]?
     // add by ak 保存删除的字幕数据用于恢复
     // add by ak 保存删除的字幕数据用于恢复
-    var deletedTittles: [(PQEditSubTitleModel, Int)]?
+    var deletedTittles: [PQEditSubTitleModel]?
 }
 }
 
 
 public class BFRecordScreenController: BFBaseViewController {
 public class BFRecordScreenController: BFBaseViewController {
@@ -134,11 +134,12 @@ public class BFRecordScreenController: BFBaseViewController {
     lazy var progreddL: UILabel = {
     lazy var progreddL: UILabel = {
         let l = UILabel()
         let l = UILabel()
         l.textAlignment = .center
         l.textAlignment = .center
-        l.font = UIFont.systemFont(ofSize: 13)
+        l.font = UIFont.systemFont(ofSize: 13, weight: .medium)
         l.textColor = .white
         l.textColor = .white
-        l.shadowColor = .black
-        l.shadowOffset = CGSize(width: 0, height: 1)
-        l.layer.opacity = 0.4
+        l.layer.shadowOpacity = 0.4
+        l.layer.shadowColor = UIColor.black.cgColor
+        l.layer.shadowOffset = CGSize(width: 0, height: 2)
+        l.layer.shadowRadius = 2
         l.text = "00:00"
         l.text = "00:00"
         return l
         return l
     }()
     }()
@@ -490,7 +491,9 @@ public class BFRecordScreenController: BFBaseViewController {
 
 
             let header = dicResult?["header"] as? [String: Any]
             let header = dicResult?["header"] as? [String: Any]
             let payload = dicResult?["payload"] as? [String: Any]
             let payload = dicResult?["payload"] as? [String: Any]
-            BFLog(1, message: "识别结果:) \((payload)!),taskId:\((header?["task_id"] as? String) ?? "taskId"), 识别时间:\(((payload?["begin_time"]) as? Int) ?? 0) ~ \(((payload?["time"]) as? Int) ?? 0) startTime:\(self?.recorderManager?.voiceModel?.startCMTime.seconds ?? 0.0)")
+
+            BFLog(1, message: "识别结果:) \(payload?["result"]) ,taskId:\((header?["task_id"] as? String) ?? "taskId"), 识别时间:\(((payload?["begin_time"]) as? Int) ?? 0) ~ \(((payload?["time"]) as? Int) ?? 0) startTime:\(self?.recorderManager?.voiceModel?.startCMTime.seconds ?? 0.0)")
+
             DispatchQueue.main.async {
             DispatchQueue.main.async {
                 // 1,保存字幕数据 begin_time是开始出现文字的时间,time 是结束文字出现的时间 单位都为毫秒,都是相对于录制音频数据整段时间。self.recorderManager.voiceModel?.startCMTime.seconds 为开始的录制的时间,开始和结束都要加上这个时差
                 // 1,保存字幕数据 begin_time是开始出现文字的时间,time 是结束文字出现的时间 单位都为毫秒,都是相对于录制音频数据整段时间。self.recorderManager.voiceModel?.startCMTime.seconds 为开始的录制的时间,开始和结束都要加上这个时差
 
 
@@ -561,7 +564,9 @@ public class BFRecordScreenController: BFBaseViewController {
 
 
                 var deletedVoices = [(PQVoiceModel, Int)]()
                 var deletedVoices = [(PQVoiceModel, Int)]()
                 // 要删除的字幕
                 // 要删除的字幕
-                var deletedTitlesTemp = [(PQEditSubTitleModel, Int)]()
+                var deletedTitlesTemp = [PQEditSubTitleModel]()
+                
+                // 查找要删除的音频和字幕数据
                 for (i, m) in sself.itemModels[sself.currItemModelIndex].voiceStickers.enumerated() {
                 for (i, m) in sself.itemModels[sself.currItemModelIndex].voiceStickers.enumerated() {
                     let originRange = CMTimeRange(start: m.startCMTime, end: CMTime(seconds: m.endCMTime.seconds - 0.02, preferredTimescale: 1000))
                     let originRange = CMTimeRange(start: m.startCMTime, end: CMTime(seconds: m.endCMTime.seconds - 0.02, preferredTimescale: 1000))
                     if CMTimeRangeGetIntersection(originRange, otherRange: newRange).duration.seconds > 0 {
                     if CMTimeRangeGetIntersection(originRange, otherRange: newRange).duration.seconds > 0 {
@@ -576,6 +581,8 @@ public class BFRecordScreenController: BFBaseViewController {
                         m.wavFilePath == tempM.wavFilePath
                         m.wavFilePath == tempM.wavFilePath
                     }
                     }
                 }
                 }
+                
+                
                 BFLog(1, message: "添加录音文件:\(model.startCMTime.seconds) -- \(model.endCMTime.seconds)")
                 BFLog(1, message: "添加录音文件:\(model.startCMTime.seconds) -- \(model.endCMTime.seconds)")
                 sself.itemModels[sself.currItemModelIndex].voiceStickers.append(model)
                 sself.itemModels[sself.currItemModelIndex].voiceStickers.append(model)
                 // 如果是图片素材同时有需要删除的录音时需要调整录音文件开始结束时间
                 // 如果是图片素材同时有需要删除的录音时需要调整录音文件开始结束时间
@@ -794,7 +801,7 @@ public class BFRecordScreenController: BFBaseViewController {
         progreddL.snp.makeConstraints { make in
         progreddL.snp.makeConstraints { make in
             make.width.equalTo(100)
             make.width.equalTo(100)
             make.centerX.equalToSuperview()
             make.centerX.equalToSuperview()
-            make.top.equalToSuperview().offset(-8)
+            make.top.equalToSuperview().offset(-5)
             make.height.equalTo(18)
             make.height.equalTo(18)
         }
         }
 
 
@@ -933,22 +940,19 @@ public class BFRecordScreenController: BFBaseViewController {
 
 
     /// 删除指定段落的所有字幕 数据
     /// 删除指定段落的所有字幕 数据
     /// - Parameter voiceModel: 删除的音频数据
     /// - Parameter voiceModel: 删除的音频数据
-    func deleteTitles(voiceModel: PQVoiceModel) -> [(PQEditSubTitleModel, Int)] {
+    func deleteTitles(voiceModel: PQVoiceModel) -> [PQEditSubTitleModel] {
         BFLog(message: "itemModels[currItemModelIndex].titleStickers  删除前:\(itemModels[currItemModelIndex].titleStickers.count) model.startCMTime.seconds: \(voiceModel.startCMTime.seconds) model.end: \(voiceModel.endCMTime.seconds)")
         BFLog(message: "itemModels[currItemModelIndex].titleStickers  删除前:\(itemModels[currItemModelIndex].titleStickers.count) model.startCMTime.seconds: \(voiceModel.startCMTime.seconds) model.end: \(voiceModel.endCMTime.seconds)")
-        var deleteTemp = [(PQEditSubTitleModel, Int)]()
+        var deleteTemp = [PQEditSubTitleModel]()
 
 
-        for (ind, sticker) in itemModels[currItemModelIndex].titleStickers.enumerated() {
-            if sticker.audioFilePath == voiceModel.wavFilePath {
-                deleteTemp.append((sticker, ind))
-            }
-        }
         // 从原数组中删除
         // 从原数组中删除
-        let arr = itemModels[currItemModelIndex].titleStickers.filter { model in
-            !deleteTemp.contains { tuple in
-                tuple.0.audioFilePath == model.audioFilePath
+        itemModels[currItemModelIndex].titleStickers.removeAll { m in
+            let su = (m.audioFilePath == voiceModel.wavFilePath)
+            if su {
+                deleteTemp.append(m)
             }
             }
+            return su
         }
         }
-        itemModels[currItemModelIndex].titleStickers = arr
+  
         BFLog(message: "itemModels[currItemModelIndex].titleStickers  删除后:\(itemModels[currItemModelIndex].titleStickers.count)")
         BFLog(message: "itemModels[currItemModelIndex].titleStickers  删除后:\(itemModels[currItemModelIndex].titleStickers.count)")
 
 
         // 清空字幕UI
         // 清空字幕UI
@@ -987,6 +991,11 @@ public class BFRecordScreenController: BFBaseViewController {
                 }
                 }
                 /// 重绘录音进度视图
                 /// 重绘录音进度视图
                 resetAllIndirectionView()
                 resetAllIndirectionView()
+                
+                // 判断是否无录音了
+                if itemModels[currItemModelIndex].materialDuraion == 0 {
+                    playBtn.isSelected = false
+                }
             }
             }
             searchStopAtRecordRange()
             searchStopAtRecordRange()
             changeWithDrawBtnLayout(3)
             changeWithDrawBtnLayout(3)
@@ -1150,13 +1159,12 @@ public class BFRecordScreenController: BFBaseViewController {
                     let model = itemModels[currItemModelIndex].voiceStickers[modelIndex]
                     let model = itemModels[currItemModelIndex].voiceStickers[modelIndex]
                     itemModels[currItemModelIndex].voiceStickers.remove(at: modelIndex)
                     itemModels[currItemModelIndex].voiceStickers.remove(at: modelIndex)
                     indirectionView?.deleteItem(index: modelIndex)
                     indirectionView?.deleteItem(index: modelIndex)
+                    
                     // 删除对应字幕
                     // 删除对应字幕
-                    let deleteTitiles = deleteTitles(voiceModel: model)
-                    for title in deleteTitiles {
-                        itemModels[currItemModelIndex].titleStickers.removeAll { model in
-                            title.0.timelineIn == model.timelineIn
-                        }
+                    itemModels[currItemModelIndex].titleStickers.removeAll { m in
+                        m.audioFilePath == model.wavFilePath
                     }
                     }
+                    
                     // 恢复被覆盖的音频
                     // 恢复被覆盖的音频
                     var tuples = action.deletedVoices
                     var tuples = action.deletedVoices
                     if tuples != nil, tuples!.count > 0 {
                     if tuples != nil, tuples!.count > 0 {
@@ -1171,7 +1179,7 @@ public class BFRecordScreenController: BFBaseViewController {
                     let titleTuples = action.deletedTittles
                     let titleTuples = action.deletedTittles
                     if titleTuples != nil, titleTuples!.count > 0 {
                     if titleTuples != nil, titleTuples!.count > 0 {
                         titleTuples?.forEach { titleTuple in
                         titleTuples?.forEach { titleTuple in
-                            itemModels[currItemModelIndex].titleStickers.insert(titleTuple.0, at: titleTuple.1)
+                            itemModels[currItemModelIndex].titleStickers.append(titleTuple)
                         }
                         }
                     }
                     }
                     jumpTime = model.startCMTime.seconds
                     jumpTime = model.startCMTime.seconds
@@ -1212,7 +1220,7 @@ public class BFRecordScreenController: BFBaseViewController {
                 let titleTuples = action.deletedTittles
                 let titleTuples = action.deletedTittles
                 if titleTuples != nil, titleTuples!.count > 0 {
                 if titleTuples != nil, titleTuples!.count > 0 {
                     titleTuples?.forEach { titleTuple in
                     titleTuples?.forEach { titleTuple in
-                        itemModels[currItemModelIndex].titleStickers.insert(titleTuple.0, at: titleTuple.1)
+                        itemModels[currItemModelIndex].titleStickers.append(titleTuple)
                     }
                     }
                 }
                 }
                 if itemModels[currItemModelIndex].mediaType == .IMAGE {
                 if itemModels[currItemModelIndex].mediaType == .IMAGE {
@@ -1605,6 +1613,10 @@ public class BFRecordScreenController: BFBaseViewController {
     func play() {
     func play() {
         BFLog(1, message: "开始播放 \(currentAssetProgress.seconds)")
         BFLog(1, message: "开始播放 \(currentAssetProgress.seconds)")
         recorderManager?.voiceModel = nil
         recorderManager?.voiceModel = nil
+        
+        itemModels[currItemModelIndex].titleStickers.sort { m1, m2 in
+            m1.timelineIn < m2.timelineIn
+        }
 
 
         isNormalPlaying = true
         isNormalPlaying = true
         if isEndPlay {
         if isEndPlay {