فهرست منبع

1,播放变音时 进行加速处理

jsonwang 3 سال پیش
والد
کامیت
d054566e00
1فایلهای تغییر یافته به همراه19 افزوده شده و 7 حذف شده
  1. 19 7
      BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenCameraManager.swift

+ 19 - 7
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenCameraManager.swift

@@ -454,26 +454,38 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
 
             // 当前播放的文件
             if playingVoiceMode == mod {
+                BFLog(2,message: "找查到mod的已经播放完成同一个")
                 return
             }
             playingVoiceMode = mod
             
             let cureentPalyURlString = BFAudioPlayer.shared.currentAudioPathURL?.absoluteString ?? ""
-            if cureentPalyURlString.replacingOccurrences(of: "file://", with: "") == mod.wavFilePath || (BFAudioPlayer.shared.player?.isPlaying ?? false){
+            if cureentPalyURlString.replacingOccurrences(of: "file://", with: "") == mod.wavFilePath && audioPlayerIsPlaying{
                 BFLog(2, message: "命中的和播放的文件路径一样? wavFilePath:\(mod.wavFilePath ?? "")")
-                if !(BFAudioPlayer.shared.player?.isPlaying ?? false) {
-                        audioPlayerIsPlaying = true
-                        BFAudioPlayer.shared.playOrPause()
-                }
+//                audioPlayerIsPlaying = true
+//                BFAudioPlayer.shared.playOrPause()
+                
+//                if !(audioPlayerIsPlaying) {
+////                        audioPlayerIsPlaying = true
+                    BFAudioPlayer.shared.setPlayingTime((currentAssetProgress - mod.startCMTime).seconds)
+////                        BFAudioPlayer.shared.playOrPause()
+//                }
+
+
                 return
             }
             
+           let ttsAudioAsset = AVURLAsset(url: URL(fileURLWithPath: mod.wavFilePath), options: avAssertOptions)
+            
+           let outTime =  ttsAudioAsset.duration.seconds - (mod.endCMTime - mod.startCMTime).seconds
             BFAudioPlayer.shared.delegate = self
             BFAudioPlayer.shared.configPlayer(audioPathURL: URL(fileURLWithPath: mod.wavFilePath))
-            BFAudioPlayer.shared.player?.rate = 2.0
+     
+            //如果音频比原来的字幕时间要长,动态加速保证和字幕时长一致。
+            BFAudioPlayer.shared.player?.rate = Float(outTime > 0 ? ttsAudioAsset.duration.seconds / (mod.endCMTime - mod.startCMTime).seconds : 1.0)
             
             let tt = currentAssetProgress - mod.startCMTime
-            BFLog(1, message: "record - tt: \(tt.seconds), curr:\(currentAssetProgress.seconds) \(needPlay)")
+            BFLog(1, message: "record - tt: \(tt.seconds), curr:\(currentAssetProgress.seconds) \(needPlay) rate:\(BFAudioPlayer.shared.player?.rate  ?? -1) 音频比字幕显示时间长 :\(outTime) \(mod.wavFilePath ?? "")")
             if CMTimeCompare(tt, .zero) == 0 {
                 if needPlay {
                     audioPlayerIsPlaying = true