|  | @@ -268,8 +268,9 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
											
												
													
														|  |      var currenStartPlayTime: CMTime = .zero
 |  |      var currenStartPlayTime: CMTime = .zero
 | 
											
												
													
														|  |      var pauseTime: Double = 0 // 停止无操作的时间点
 |  |      var pauseTime: Double = 0 // 停止无操作的时间点
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    var assetPlayer: AVPlayer = AVPlayer(playerItem: nil) // 原视频音频播放器
 |  | 
 | 
											
												
													
														|  | -    var recordPlayer: AVPlayer = AVPlayer(playerItem: nil) // 录音音频播放器
 |  | 
 | 
											
												
													
														|  | 
 |  | +    var assetPlayer     : AVPlayer = AVPlayer(playerItem: nil)   // 原视频音频播放器
 | 
											
												
													
														|  | 
 |  | +    var recordPlayer    : AVPlayer = AVPlayer(playerItem: nil)   // 录音音频播放器
 | 
											
												
													
														|  | 
 |  | +    var bgmPlayer = BFMusicManager()   // 背景音乐音频播放器
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      var hadPrepareToPlayRecord = false // 录音播放器准备
 |  |      var hadPrepareToPlayRecord = false // 录音播放器准备
 | 
											
												
													
														|  |      var playView: GPUImageView? // 视频展示视图
 |  |      var playView: GPUImageView? // 视频展示视图
 | 
											
										
											
												
													
														|  | @@ -664,10 +665,10 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
											
												
													
														|  |              wself.bgmModel?.volume = Int(musicVolume)
 |  |              wself.bgmModel?.volume = Int(musicVolume)
 | 
											
												
													
														|  |              wself.originalVolume = originalVolume / 100.0
 |  |              wself.originalVolume = originalVolume / 100.0
 | 
											
												
													
														|  |              wself.choseMusicPanel.musicVolume = Int(musicVolume)
 |  |              wself.choseMusicPanel.musicVolume = Int(musicVolume)
 | 
											
												
													
														|  | -            if !wself.isNormalPlaying, !wself.isRecording {
 |  | 
 | 
											
												
													
														|  | -                
 |  | 
 | 
											
												
													
														|  | -                wself.assetPlayer.volume = wself.originalVolume
 |  | 
 | 
											
												
													
														|  | -            }
 |  | 
 | 
											
												
													
														|  | 
 |  | +            wself.assetPlayer.volume = wself.originalVolume
 | 
											
												
													
														|  | 
 |  | +//            if !wself.isNormalPlaying, !wself.isRecording {
 | 
											
												
													
														|  | 
 |  | +//
 | 
											
												
													
														|  | 
 |  | +//            }
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          return audioSettingView
 |  |          return audioSettingView
 | 
											
										
											
												
													
														|  | @@ -1732,6 +1733,7 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      @objc func endRecord() {
 |  |      @objc func endRecord() {
 | 
											
												
													
														|  |          // 存储录音
 |  |          // 存储录音
 | 
											
												
													
														|  | 
 |  | +        
 | 
											
												
													
														|  |          if !isRecording {
 |  |          if !isRecording {
 | 
											
												
													
														|  |              return
 |  |              return
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
										
											
												
													
														|  | @@ -2138,20 +2140,26 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      // MARK: - 音视频处理
 |  |      // MARK: - 音视频处理
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | 
 |  | +    
 | 
											
												
													
														|  | 
 |  | +    /// 查找录音播放
 | 
											
												
													
														|  | 
 |  | +    /// - Parameters:
 | 
											
												
													
														|  | 
 |  | +    ///   - currentT: 当前播放进度时刻
 | 
											
												
													
														|  | 
 |  | +    ///   - periodicTimeObserver: 每次刷新要执行的block
 | 
											
												
													
														|  | 
 |  | +    ///   - didPlayToEndTime: 录音播放结束后的block
 | 
											
												
													
														|  | 
 |  | +    ///   - _: 播放失败的block
 | 
											
												
													
														|  |      func playRecord(at currentT: CMTime, periodicTimeObserver: @escaping (_ time: CMTime, _ currentItem: AVPlayerItem) -> Void, didPlayToEndTime: @escaping (_ recordedInfo: (Int, PQVoiceModel)?, _ currentItem: AVPlayerItem?) -> Void, playFailed _: @escaping (_ recordedInfo: (Int, PQVoiceModel)?, _ currentItem: AVPlayerItem?) -> Void) {
 |  |      func playRecord(at currentT: CMTime, periodicTimeObserver: @escaping (_ time: CMTime, _ currentItem: AVPlayerItem) -> Void, didPlayToEndTime: @escaping (_ recordedInfo: (Int, PQVoiceModel)?, _ currentItem: AVPlayerItem?) -> Void, playFailed _: @escaping (_ recordedInfo: (Int, PQVoiceModel)?, _ currentItem: AVPlayerItem?) -> Void) {
 | 
											
												
													
														|  |   
 |  |   
 | 
											
												
													
														|  |          //add by ak 使用的音频数据
 |  |          //add by ak 使用的音频数据
 | 
											
												
													
														|  |          let  useVoiceStickers = itemModels[currItemModelIndex].getUsedVoices()
 |  |          let  useVoiceStickers = itemModels[currItemModelIndex].getUsedVoices()
 | 
											
												
													
														|  |          
 |  |          
 | 
											
												
													
														|  |          //音量设置判断使用原录音数据
 |  |          //音量设置判断使用原录音数据
 | 
											
												
													
														|  | -        if itemModels[currItemModelIndex].voiceStickers.first(where: { m in
 |  | 
 | 
											
												
													
														|  | -            CMTimeCompare(m.startCMTime, currentT) <= 0 && CMTimeCompare(currentT, m.endCMTime) <= 0
 |  | 
 | 
											
												
													
														|  | -        }) != nil {
 |  | 
 | 
											
												
													
														|  | -            if assetPlayer.volume != originalVolume {
 |  | 
 | 
											
												
													
														|  | -                assetPlayer.volume = originalVolume
 |  | 
 | 
											
												
													
														|  | -            }
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | 
 |  | +//        if itemModels[currItemModelIndex].voiceStickers.first(where: { m in
 | 
											
												
													
														|  | 
 |  | +//            CMTimeCompare(m.startCMTime, currentT) <= 0 && CMTimeCompare(currentT, m.endCMTime) <= 0
 | 
											
												
													
														|  | 
 |  | +//        }) != nil {
 | 
											
												
													
														|  | 
 |  | +//            if assetPlayer.volume != originalVolume {
 | 
											
												
													
														|  | 
 |  | +//                assetPlayer.volume = originalVolume
 | 
											
												
													
														|  | 
 |  | +//            }
 | 
											
												
													
														|  | 
 |  | +//        }
 | 
											
												
													
														|  |  //        BFLog(1, message: "volume:\(assetPlayer.volume ?? -1)")
 |  |  //        BFLog(1, message: "volume:\(assetPlayer.volume ?? -1)")
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          if currentPlayRecordIndex == -3 { // 刚录音完,不需要播放
 |  |          if currentPlayRecordIndex == -3 { // 刚录音完,不需要播放
 | 
											
										
											
												
													
														|  | @@ -2172,7 +2180,6 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
											
												
													
														|  |              return
 |  |              return
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |          BFLog(1, message: "当前时间:\(CMTimeGetSeconds(currentT)), 找到的音频:\(recordedAudio.startCMTime.seconds) ~ \(recordedAudio.endCMTime.seconds), \(recordedAudio.wavFilePath ?? "")")
 |  |          BFLog(1, message: "当前时间:\(CMTimeGetSeconds(currentT)), 找到的音频:\(recordedAudio.startCMTime.seconds) ~ \(recordedAudio.endCMTime.seconds), \(recordedAudio.wavFilePath ?? "")")
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  |          // 创建播放器
 |  |          // 创建播放器
 | 
											
												
													
														|  |          if (recordPlayer.currentItem?.asset as? AVURLAsset)?.url.lastPathComponent != (recordedAudio.wavFilePath as NSString?)?.lastPathComponent {
 |  |          if (recordPlayer.currentItem?.asset as? AVURLAsset)?.url.lastPathComponent != (recordedAudio.wavFilePath as NSString?)?.lastPathComponent {
 | 
											
												
													
														|  |              let newItem = AVPlayerItem(url: URL(fileURLWithPath: recordedAudio.wavFilePath))
 |  |              let newItem = AVPlayerItem(url: URL(fileURLWithPath: recordedAudio.wavFilePath))
 | 
											
										
											
												
													
														|  | @@ -2198,20 +2205,20 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
											
												
													
														|  |                  }
 |  |                  }
 | 
											
												
													
														|  |                  wself.hadPrepareToPlayRecord = false
 |  |                  wself.hadPrepareToPlayRecord = false
 | 
											
												
													
														|  |                  wself.currentPlayRecordIndex = -1
 |  |                  wself.currentPlayRecordIndex = -1
 | 
											
												
													
														|  | -//                wself.recordPlayer.volume = 0
 |  | 
 | 
											
												
													
														|  | -//                wself.assetPlayer.volume = wself.musicVolume
 |  | 
 | 
											
												
													
														|  | 
 |  | +                
 | 
											
												
													
														|  | 
 |  | +                wself.assetPlayer.volume = wself.originalVolume
 | 
											
												
													
														|  | 
 |  | +                
 | 
											
												
													
														|  |                  BFLog(3, message: "播放结束")
 |  |                  BFLog(3, message: "播放结束")
 | 
											
												
													
														|  |                  didPlayToEndTime((shouldPlayRecordIndex, recordedAudio), newItem)
 |  |                  didPlayToEndTime((shouldPlayRecordIndex, recordedAudio), newItem)
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  |  //            recordPlayer.removeTimeObserver(recordPlayerTimeObserver as Any)
 |  |  //            recordPlayer.removeTimeObserver(recordPlayerTimeObserver as Any)
 | 
											
												
													
														|  |  //            recordPlayerTimeObserver?.invalidate()
 |  |  //            recordPlayerTimeObserver?.invalidate()
 | 
											
												
													
														|  |              //MARK: 声音播放器播放进度回调
 |  |              //MARK: 声音播放器播放进度回调
 | 
											
												
													
														|  | -            recordPlayerTimeObserver = recordPlayer.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 1000), queue: DispatchQueue.global()) { [weak self, weak recordPlayer] time in
 |  | 
 | 
											
												
													
														|  | -                guard let wself = self, let rPlay = recordPlayer else {
 |  | 
 | 
											
												
													
														|  | -                    BFLog(3, message: "wself为空")
 |  | 
 | 
											
												
													
														|  | -                    return
 |  | 
 | 
											
												
													
														|  | 
 |  | +            recordPlayerTimeObserver = recordPlayer.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 1000), queue: DispatchQueue.global()) { [weak self] time in
 | 
											
												
													
														|  | 
 |  | +                guard let wself = self else { return }
 | 
											
												
													
														|  | 
 |  | +                if time.seconds > 0 {
 | 
											
												
													
														|  | 
 |  | +                    wself.assetPlayer.volume = 0 //wself.originalVolume * 0.6                    
 | 
											
												
													
														|  |                  }
 |  |                  }
 | 
											
												
													
														|  | -//                BFLog(1, message: "当前播放--- \(time.seconds), \(rPlay.currentItem?.duration.seconds ?? 0)")
 |  | 
 | 
											
												
													
														|  |                  if CMTimeGetSeconds(wself.currenStartPlayTime) <= 0 {
 |  |                  if CMTimeGetSeconds(wself.currenStartPlayTime) <= 0 {
 | 
											
												
													
														|  |                      BFLog(message: "重新更新开始播放进度\(#function)-\(wself.currenStartPlayTime.seconds)")
 |  |                      BFLog(message: "重新更新开始播放进度\(#function)-\(wself.currenStartPlayTime.seconds)")
 | 
											
												
													
														|  |                      wself.currenStartPlayTime = time
 |  |                      wself.currenStartPlayTime = time
 | 
											
										
											
												
													
														|  | @@ -2219,9 +2226,6 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
											
												
													
														|  |                  let progressTime = CMTime(seconds: CMTimeGetSeconds(time) - CMTimeGetSeconds(wself.currenStartPlayTime), preferredTimescale: 1000)
 |  |                  let progressTime = CMTime(seconds: CMTimeGetSeconds(time) - CMTimeGetSeconds(wself.currenStartPlayTime), preferredTimescale: 1000)
 | 
											
												
													
														|  |                  BFLog(message: "progressTime进度\(#function)-\(progressTime.seconds)")
 |  |                  BFLog(message: "progressTime进度\(#function)-\(progressTime.seconds)")
 | 
											
												
													
														|  |                  periodicTimeObserver(progressTime, newItem)
 |  |                  periodicTimeObserver(progressTime, newItem)
 | 
											
												
													
														|  | -//                if (rPlay.currentItem?.currentTime().seconds ?? 0) > (rPlay.currentItem?.duration.seconds ?? 0) - 0.1 {
 |  | 
 | 
											
												
													
														|  | -//                    didPlayToEndTime((shouldPlayRecordIndex, recordedAudio), newItem)
 |  | 
 | 
											
												
													
														|  | -//                }
 |  | 
 | 
											
												
													
														|  |              } as? NSKeyValueObservation
 |  |              } as? NSKeyValueObservation
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |          if currMediaType == .Video {
 |  |          if currMediaType == .Video {
 | 
											
										
											
												
													
														|  | @@ -2323,7 +2327,7 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
											
												
													
														|  |          BFLog(1, message: "开始播放 \(currentAssetProgress.seconds)")
 |  |          BFLog(1, message: "开始播放 \(currentAssetProgress.seconds)")
 | 
											
												
													
														|  |          recorderManager?.voiceModel = nil
 |  |          recorderManager?.voiceModel = nil
 | 
											
												
													
														|  |          events.append(WithDrawModel(type: 1, timestamp: currentAssetProgress, recordItem: rscurrentManager.recordItem!))
 |  |          events.append(WithDrawModel(type: 1, timestamp: currentAssetProgress, recordItem: rscurrentManager.recordItem!))
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | 
 |  | + 
 | 
											
												
													
														|  |          itemModels[currItemModelIndex].titleStickers.sort { m1, m2 in
 |  |          itemModels[currItemModelIndex].titleStickers.sort { m1, m2 in
 | 
											
												
													
														|  |              CMTimeCompare(m1.timelineIn, m2.timelineIn) < 0
 |  |              CMTimeCompare(m1.timelineIn, m2.timelineIn) < 0
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
										
											
												
													
														|  | @@ -2350,9 +2354,19 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |              rscurrentManager.currentAssetProgress = .zero
 |  |              rscurrentManager.currentAssetProgress = .zero
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        bgmPlayer.player.volume = Float(choseMusicPanel.musicVolume) / 100.0
 | 
											
												
													
														|  | 
 |  | +        assetPlayer.volume = originalVolume
 | 
											
												
													
														|  | 
 |  | +        
 | 
											
												
													
														|  | 
 |  | +        if currItemModelIndex == 0 && currentAssetProgress == .zero{
 | 
											
												
													
														|  | 
 |  | +            bgmPlayer.player.seek(to: .zero) {[weak self] _ in
 | 
											
												
													
														|  | 
 |  | +                self?.bgmPlayer.play()
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +        }else{
 | 
											
												
													
														|  | 
 |  | +            bgmPlayer.play()
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  |          
 |  |          
 | 
											
												
													
														|  |          rscurrentManager.play()
 |  |          rscurrentManager.play()
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      public func pause() {
 |  |      public func pause() {
 | 
											
										
											
												
													
														|  | @@ -2368,7 +2382,10 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          // 暂停状态
 |  |          // 暂停状态
 | 
											
												
													
														|  |          updatePlayBtnStatus()
 |  |          updatePlayBtnStatus()
 | 
											
												
													
														|  | 
 |  | +        
 | 
											
												
													
														|  | 
 |  | +        bgmPlayer.pause()
 | 
											
												
													
														|  |          rscurrentManager.pause()
 |  |          rscurrentManager.pause()
 | 
											
												
													
														|  | 
 |  | +        
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      public func fetchMaterial(_ phAsset:[PHAsset]) {
 |  |      public func fetchMaterial(_ phAsset:[PHAsset]) {
 | 
											
										
											
												
													
														|  | @@ -2517,7 +2534,7 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
											
												
													
														|  |                  DispatchQueue.main.async { [weak self] in
 |  |                  DispatchQueue.main.async { [weak self] in
 | 
											
												
													
														|  |                      guard let wself = self else { return }
 |  |                      guard let wself = self else { return }
 | 
											
												
													
														|  |                      
 |  |                      
 | 
											
												
													
														|  | -                    BFLog(message: "更新录音进度\(#function)-\(wself.currentAssetProgress.seconds )")
 |  | 
 | 
											
												
													
														|  | 
 |  | +                    BFLog(message: "更新录音进度\(#function) - \(wself.currentAssetProgress.seconds )")
 | 
											
												
													
														|  |                      wself.progreddL.text = String(format: "%@", CMTimeGetSeconds(time).formatDurationToHMS())
 |  |                      wself.progreddL.text = String(format: "%@", CMTimeGetSeconds(time).formatDurationToHMS())
 | 
											
												
													
														|  |                      let su = !wself.isDragingProgressSlder || wself.isRecording || wself.isNormalPlaying
 |  |                      let su = !wself.isDragingProgressSlder || wself.isRecording || wself.isNormalPlaying
 | 
											
												
													
														|  |                      if su { // 不拖动,正常播放和录音时更新进度条
 |  |                      if su { // 不拖动,正常播放和录音时更新进度条
 | 
											
										
											
												
													
														|  | @@ -2593,7 +2610,7 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
											
												
													
														|  |                  DispatchQueue.main.async { [weak self] in
 |  |                  DispatchQueue.main.async { [weak self] in
 | 
											
												
													
														|  |                      guard let wself = self else { return }
 |  |                      guard let wself = self else { return }
 | 
											
												
													
														|  |                      
 |  |                      
 | 
											
												
													
														|  | -                    BFLog(message: "更新录音进度\(#function)- \(wself.currentAssetProgress.seconds)")
 |  | 
 | 
											
												
													
														|  | 
 |  | +                    BFLog(message: "更新录音进度\(#function) - \(wself.currentAssetProgress.seconds)")
 | 
											
												
													
														|  |                      wself.progreddL.text = String(format: "%@", CMTimeGetSeconds(wself.currentAssetProgress).formatDurationToHMS())
 |  |                      wself.progreddL.text = String(format: "%@", CMTimeGetSeconds(wself.currentAssetProgress).formatDurationToHMS())
 | 
											
												
													
														|  |                  }
 |  |                  }
 | 
											
												
													
														|  |                  assetPlayer.seek(to: currentAssetProgress, toleranceBefore: CMTime(value: 1, timescale: 1_000_000), toleranceAfter: CMTime(value: 1, timescale: 1_000_000)) { _ in
 |  |                  assetPlayer.seek(to: currentAssetProgress, toleranceBefore: CMTime(value: 1, timescale: 1_000_000), toleranceAfter: CMTime(value: 1, timescale: 1_000_000)) { _ in
 | 
											
										
											
												
													
														|  | @@ -2659,7 +2676,8 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
											
												
													
														|  |      
 |  |      
 | 
											
												
													
														|  |      func hadChoosed(music:PQVoiceModel?) {
 |  |      func hadChoosed(music:PQVoiceModel?) {
 | 
											
												
													
														|  |          bgmModel = music
 |  |          bgmModel = music
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | 
 |  | +        bgmPlayer.replaceCurrentItem(musicPath: bgmModel?.musicPath)
 | 
											
												
													
														|  | 
 |  | +        
 | 
											
												
													
														|  |          if let model = music {
 |  |          if let model = music {
 | 
											
												
													
														|  |              
 |  |              
 | 
											
												
													
														|  |              BFEventTrackAdaptor.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_musicChangerButton, pageSource: .sp_speekPage,extParams: ["musicID":bgmModel?.musicId ?? ""],commonParams: commonParams())
 |  |              BFEventTrackAdaptor.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_musicChangerButton, pageSource: .sp_speekPage,extParams: ["musicID":bgmModel?.musicId ?? ""],commonParams: commonParams())
 |