소스 검색

图片模式修改;
插入录制时字幕错误的问题fix

胡志强 3 년 전
부모
커밋
9df65345fe

+ 23 - 17
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -1100,23 +1100,26 @@ public class BFRecordScreenController: BFBaseViewController {
                             if mod.startCMTime.seconds >= model.startCMTime.seconds {
                                 mod.startCMTime = mod.startCMTime + duration
                                 mod.endCMTime = mod.endCMTime + duration
+                                
+                                //对应的字幕进行后移修改
+                                let titleList = recordItem.titleStickers.filter({ title in
+                                    title.recordId == mod.recordId
+                                })
+                                titleList.forEach { t in
+                                    t.timelineIn = t.timelineIn + duration
+                                    t.timelineOut = t.timelineOut + duration
+                                }
+                                //对应的变声进行后移修改
+                                let voiceList = recordItem.voiceChangeStickers.filter({ voice in
+                                    voice.recordId == mod.recordId
+                                })
+                                voiceList.forEach { mod in
+                                    mod.startCMTime = mod.startCMTime + duration
+                                    mod.endCMTime = mod.endCMTime + duration
+                                }
                             }
                         })
-                        
-                        recordItem.voiceChangeStickers.forEach({ mod in
-                            if mod.startCMTime.seconds >= model.startCMTime.seconds {
-                                mod.startCMTime = mod.startCMTime + duration
-                                mod.endCMTime = mod.endCMTime + duration
-                            }
-                        })
-
-                        recordItem.titleStickers.forEach({ mod in
-                            if mod.timelineIn.seconds >= model.startCMTime.seconds {
-                                mod.timelineIn = mod.timelineIn + duration
-                                mod.timelineOut = mod.timelineOut + duration
-                            }
-                        })
-                        
+   
                     }
                 }
                 
@@ -1223,7 +1226,7 @@ public class BFRecordScreenController: BFBaseViewController {
                 let currShowSubtitle = recordItem.titleStickers[showSubtitleIndex]
                 
                 if CMTimeCompare(currShowSubtitle.timelineIn, time) <= 0, CMTimeCompare(currShowSubtitle.timelineOut, time) > 0 {
-                    // 已存在字幕
+                    // 已存在不同的字幕
                     if subtitleLabel.text != currShowSubtitle.text {
                         subtitleLabel.text = currShowSubtitle.text
                         setSubtitleStyle(settingModel: subtitleSettingView.subtitle.setting)
@@ -1243,6 +1246,7 @@ public class BFRecordScreenController: BFBaseViewController {
                 }
             }
             
+            BFLog(1, message: "test:\(findShowSubtitle?.text ?? "none")")
             if findShowSubtitle != nil, subtitleLabel.text != findShowSubtitle!.text {
                 subtitleLabel.text = findShowSubtitle!.text
                 setSubtitleStyle(settingModel: subtitleSettingView.subtitle.setting)
@@ -2146,9 +2150,9 @@ public class BFRecordScreenController: BFBaseViewController {
     func play() {
         //如果当前段有没有转完的发音人显示 Loadingview
         if(!voiceChangeStickerFinish(itemIndex: currItemModelIndex,isShowLoadView: true)){
-          
             return
         }
+
         BFLog(1, message: "开始播放 \(currentAssetProgress.seconds)")
         recorderManager?.voiceModel = nil
         events.append(WithDrawModel(type: 1, timestamp: currentAssetProgress, recordItem: rscurrentManager.recordItem!))
@@ -2715,6 +2719,8 @@ public extension BFRecordScreenController {
             recordStartPlayTime = currentAssetProgress
             currenStartPlayTime = CMTime.zero
         }
+        
+        // 音
         playRecord(at: time, periodicTimeObserver: { [weak self] currentT, _ in
             
             guard let wself = self else { return }

+ 65 - 3
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenImageManager.swift

@@ -7,9 +7,13 @@
 
 import Foundation
 import CoreMedia
+import AVFoundation
+import BFCommonKit
 
 class BFRecordScreenImageManager : BFRecordScreenBaseManager{
     
+    fileprivate var timerr:Timer?
+    var isPlaying = false
     override func resetEnv() {
         // 重置指针
         currentAssetProgress = .zero
@@ -22,7 +26,64 @@ class BFRecordScreenImageManager : BFRecordScreenBaseManager{
     }
     
     override func play() {
-        dele?.startPlayRecord(time: currentAssetProgress)
+        // 找到当前要播放的音频
+        timerr?.invalidate()
+        
+        if ((recordItem?.materialDuraion ?? .zero) - currentAssetProgress).seconds < 0.05 {
+            currentAssetProgress = .zero
+        }
+
+        checkCurrentPlayStatus()
+        
+        let startPlayTime = Date()
+        let startProgress = currentAssetProgress
+        
+        timerr = Timer.scheduledTimer(withTimeInterval: 0.01, repeats: true, block: {[weak self] _ in
+            guard let wself = self else { return }
+            // MARK: 进度计时器
+            let currTime = startProgress + CMTime(seconds: Date().timeIntervalSince(startPlayTime), preferredTimescale: 1000)
+            wself.dele?.progreddL.text = String(format: "%@", max(0, min(currTime.seconds, (wself.recordItem?.materialDuraion.seconds ?? 0))).formatDurationToHMS())
+            wself.currentAssetProgress = min(currTime, (wself.recordItem?.materialDuraion ?? .zero))
+            wself.dele?.progressThumV.progress = wself.currentAssetProgress
+            wself.dele?.updateSubtitle(time: wself.currentAssetProgress)
+            
+            if currTime.seconds >= (wself.recordItem?.materialDuraion.seconds ?? 0) {
+                wself.dele?.pause()
+                wself.isPlaying = false
+                return
+            }
+            
+            wself.checkCurrentPlayStatus()
+        })
+        RunLoop.current.add(timerr!, forMode: .common)
+    }
+    
+    func checkCurrentPlayStatus(){
+        if let voice = recordItem?.voiceStickers.first(where: { mod in
+            (mod.startCMTime - currentAssetProgress).seconds <= 0.05 && (mod.endCMTime - currentAssetProgress).seconds > 0.05
+        }){
+            let su = (recordPlayer?.currentItem?.asset as? AVURLAsset)?.url.lastPathComponent != (voice.wavFilePath as NSString?)?.lastPathComponent
+            if (recordPlayer?.currentItem == nil) || su || (!su && !isPlaying){
+                isPlaying = true
+                recordPlayer?.replaceCurrentItem(with: AVPlayerItem(url: URL(fileURLWithPath: voice.wavFilePath)))
+                let tt = max(CMTime.zero, currentAssetProgress - voice.startCMTime)
+                BFLog(1, message: "tt:\(tt.seconds)")
+                recordPlayer?.seek(to: tt , toleranceBefore: CMTime(seconds: 1, preferredTimescale: 10000), toleranceAfter: CMTime(seconds: 1, preferredTimescale: 10000), completionHandler: {[weak self] isfinished in
+                    guard let wself = self else { return }
+                    
+                    wself.recordPlayer?.play()
+//                    if isfinished {
+//                    }
+                })
+            }
+            
+        }
+    }
+    
+    override func pause() {
+        timerr?.invalidate()
+        timerr = nil
+        
     }
     
     override func deleteRecord(at: CMTime) {
@@ -49,7 +110,6 @@ class BFRecordScreenImageManager : BFRecordScreenBaseManager{
             // 更新进度
             dele?.resetCurrentProgress()
             
-            
             for (index, item) in recordItem.voiceStickers.enumerated() {
                 if index >= dele?.isStopAtRecordRange ?? 0 {
                     // 注:开始时间减去duration or 等一前一段录音的结束时间
@@ -83,6 +143,8 @@ class BFRecordScreenImageManager : BFRecordScreenBaseManager{
     override func clean() {
         super.clean()
         filter.removeTarget(playView)
-        
     }
+    
+    //MARK: - 播放逻辑
+    
 }