فهرست منبع

录音覆盖的问题fix

harry 3 سال پیش
والد
کامیت
aafd271cf4
1فایلهای تغییر یافته به همراه29 افزوده شده و 15 حذف شده
  1. 29 15
      BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

+ 29 - 15
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -309,6 +309,8 @@ public class BFRecordScreenController: BFBaseViewController {
             BFLog(1, message: "haveSpeak is:\(haveSpeak),noHaveSpeak is:\(noHaveSpeak)")
             self?.haveSpeakVolume = haveSpeak / 100.0
             self?.noSpeakVolume = noHaveSpeak / 100.0
+            
+//            self?.assetPlayer?.volume = self?.noSpeakVolume
         }
 
         return audioSettingView
@@ -457,18 +459,19 @@ public class BFRecordScreenController: BFBaseViewController {
                 if let sself = self, let model = voideModel, FileManager.default.fileExists(atPath: model.wavFilePath ?? "") {
                     // 加入到语音数组里
                     model.endTime = sself.currentAssetProgress.seconds
-
+                    
+                    let recordItem = sself.itemModels[sself.currItemModelIndex]
                     // ********** 开始处理冲突的录制部分
                     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() {
+                    for (i, m) in recordItem.voiceStickers.enumerated() {
                         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))
-                            for titleS in sself.itemModels[sself.currItemModelIndex].titleStickers {
+                            for titleS in recordItem.titleStickers {
                                 if titleS.audioFilePath == m.wavFilePath {
                                     
                                 }
@@ -496,22 +499,27 @@ public class BFRecordScreenController: BFBaseViewController {
                     sself.events.append(event)
                     
                     
-                    if sself.itemModels[sself.currItemModelIndex].mediaType == .IMAGE {
+                    if recordItem.mediaType == .IMAGE {
                         var duration: Double = 0
-                        sself.itemModels[sself.currItemModelIndex].voiceStickers.forEach { temp in
+                        recordItem.voiceStickers.forEach { temp in
                             temp.duration = "\(temp.endTime - temp.startTime)"
                             duration = duration + (temp.endTime - temp.startTime)
                         }
                         sself.itemModels[sself.currItemModelIndex].materialDuraion = Double(String(format: "%.3f", duration)) ?? 0
                         self?.isEndPlay = true
                         // 录制结束显示播放按钮
-                        (sself.collectionView.cellForItem(at: IndexPath(item: sself.currItemModelIndex, section: 0)) as? BFImageCoverViewCell)?.playBtn.isSelected = sself.itemModels[sself.currItemModelIndex].voiceStickers.count <= 0
+                        (sself.collectionView.cellForItem(at: IndexPath(item: sself.currItemModelIndex, section: 0)) as? BFImageCoverViewCell)?.playBtn.isSelected = recordItem.voiceStickers.count <= 0
                     }
                     DispatchQueue.main.async { [weak self] in
                         // 录音完,重绘撤销按钮,更新录音按钮,
                         self?.changeWithDrawBtnLayout(true)
                         // 注:在录制结束时矫正当前位置,避免跟指针无法对其
-                        self?.indirectionView?.resetCurrentItem(start: model.startTime, end: model.endTime)
+                        if deletedVoices.count == 0 {
+                            self?.indirectionView?.resetCurrentItem(start: model.startTime, end: model.endTime)
+                        }else {
+                            self?.indirectionView?.resetAllSubViews(items: recordItem.voiceStickers, percenWidth: recordItem.mediaType == .IMAGE ? (self?.progressThumV.thumbImageWidth ?? 0) / 2.0 : 0, totalDuration: recordItem.materialDuraion)
+
+                        }
                         // 矫正进度
                         self?.resetCurrentProgress()
                         self?.deleteRecordBtn.isHidden = true
@@ -1028,10 +1036,12 @@ public class BFRecordScreenController: BFBaseViewController {
             }
             searchStopAtRecordRange()
             let itemModel = itemModels[currItemModelIndex]
+            
+            // 重置进度条
+            indirectionView?.resetAllSubViews(items: itemModels[currItemModelIndex].voiceStickers, percenWidth: itemModels[currItemModelIndex].mediaType == .IMAGE ? (progressThumV.thumbImageWidth ) / 2.0 : 0, totalDuration: itemModels[currItemModelIndex].materialDuraion)
+
             // 如果是图片需重置播放按钮
             if itemModel.mediaType == .IMAGE {
-                // 重置进度条
-                indirectionView?.resetAllSubViews(items: itemModels[currItemModelIndex].voiceStickers, percenWidth: progressThumV.thumbImageWidth / 2.0, totalDuration: itemModels[currItemModelIndex].materialDuraion)
                 (collectionView.cellForItem(at: IndexPath(item: currItemModelIndex, section: 0)) as? BFImageCoverViewCell)?.playBtn.isSelected = itemModels[currItemModelIndex].voiceStickers.count <= 0
             }
         }
@@ -1237,11 +1247,12 @@ public class BFRecordScreenController: BFBaseViewController {
                 periodicTimeObserver(CMTime(seconds: CMTimeGetSeconds(time) - CMTimeGetSeconds(self?.currenStartPlayTime ?? CMTime.zero), preferredTimescale: 1000), newItem)
             } as? NSKeyValueObservation
         }
-        if recordPlayer?.currentItem?.duration.timescale == 0 {
-            BFLog(1, message: "时间timescale  == 0")
-            playFailed((shouldPlayRecordIndex, recordedAudio) as? (Int, PQVoiceModel), recordPlayer?.currentItem)
-            return
-        }
+        
+//        if recordPlayer?.currentItem?.duration.timescale == 0 {
+//            BFLog(1, message: "时间timescale  == 0")
+//            playFailed((shouldPlayRecordIndex, recordedAudio) as? (Int, PQVoiceModel), recordPlayer?.currentItem)
+//            return
+//        }
         synced(currentPlayRecordIndex) { [weak self] in
             guard let sself = self else {
                 return
@@ -1249,10 +1260,13 @@ public class BFRecordScreenController: BFBaseViewController {
             BFLog(1, message: "判断是否开始录音播放** hadPrepareToPlayRecord:\(hadPrepareToPlayRecord), currentPlayRecordIndex:\(currentPlayRecordIndex), isNormalPlaying :\(sself.isNormalPlaying),\(recordPlayer?.currentItem?.duration.timescale ?? 0),\(CMTimeGetSeconds(currentT) >= recordedAudio.startTime),\(CMTimeGetSeconds(currentT) <= recordedAudio.endTime - 0.2)")
 
             if !hadPrepareToPlayRecord,
-               recordPlayer?.currentItem?.duration.timescale != 0,
                CMTimeGetSeconds(currentT) >= (recordedAudio.startTime - 0.1),
                CMTimeGetSeconds(currentT) <= recordedAudio.endTime - 0.2 // 这个条件是避免录音结束后有小幅度回退导致播放最新录音
             {
+                if itemModels[currItemModelIndex].mediaType == .VIDEO && recordPlayer?.currentItem?.duration.timescale == 0{
+                    return
+
+                }
                 // 应当开始播放了
                 // 两个逻辑:如果在播,则跳过;如果暂停拖动到中间,则seek
                 if currentPlayRecordIndex == -1, sself.isNormalPlaying {