|
@@ -91,8 +91,6 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
|
|
|
// wself.currentAssetProgress = CMTime(seconds: (currTime + wself.currPlayTime).seconds, preferredTimescale: 1000)
|
|
|
|
|
|
BFLog(message: "当前播放器状态: \(wself.avplayer.timeControlStatus.rawValue) \(wself.currentAssetProgress.seconds)")
|
|
|
-
|
|
|
- wself.playRecordVoice()
|
|
|
}
|
|
|
// BFLog(1, message: "拖动 currTime: \(currTime.seconds)")
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
@@ -458,15 +456,16 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
|
|
|
}
|
|
|
|
|
|
func playRecordVoice(needPlay: Bool = true) {
|
|
|
+
|
|
|
// 三种状态值
|
|
|
// case paused = 0
|
|
|
// case waitingToPlayAtSpecifiedRate = 1
|
|
|
// case playing = 2
|
|
|
- if recordPlayer?.timeControlStatus == .playing || recordPlayer?.timeControlStatus == .waitingToPlayAtSpecifiedRate {
|
|
|
- BFLog(2, message: "recordPlayer is playering 本次查找无效,有播放任务")
|
|
|
+ if (BFAudioPlayer.shared.player?.isPlaying ?? false){
|
|
|
+ BFLog(2, message: "is playering 本次查找无效,有播放任务")
|
|
|
return
|
|
|
}
|
|
|
- BFLog(message: "开始查找!!!!当前进度:\(currentAssetProgress.seconds) \(recordPlayer?.timeControlStatus.rawValue ?? -1)")
|
|
|
+ BFLog(message: "开始查找!!!!当前进度:\(currentAssetProgress.seconds)")
|
|
|
|
|
|
// 播放音频
|
|
|
var useVoiceStickers = [PQVoiceModel]()
|
|
@@ -483,51 +482,26 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
|
|
|
BFLog(message: "找到音频开始时间:\(mod.startCMTime.seconds)结束 \(mod.endCMTime.seconds) currentAssetProgress is \(currentAssetProgress.seconds)")
|
|
|
|
|
|
// 当前播放的文件
|
|
|
- let cureentPalyURlString = (recordPlayer?.currentItem?.asset as? AVURLAsset)?.url.absoluteString ?? ""
|
|
|
- if cureentPalyURlString.replacingOccurrences(of: "file://", with: "") == mod.wavFilePath && recordPlayer?.timeControlStatus != .playing {
|
|
|
- BFLog(2, message: "命中的和播放的文件路径一样? wavFilePath:\(mod.wavFilePath ?? "") recordPlayer Status \(recordPlayer?.timeControlStatus.rawValue ?? -1)")
|
|
|
+
|
|
|
+ let cureentPalyURlString = BFAudioPlayer.shared.currentAudioPathURL?.absoluteString ?? ""
|
|
|
+ if cureentPalyURlString.replacingOccurrences(of: "file://", with: "") == mod.wavFilePath{
|
|
|
+ BFLog(2, message: "命中的和播放的文件路径一样? wavFilePath:\(mod.wavFilePath ?? "")")
|
|
|
return
|
|
|
}
|
|
|
- recordPlayer?.replaceCurrentItem(with: AVPlayerItem(url: URL(fileURLWithPath: mod.wavFilePath)))
|
|
|
+
|
|
|
+ BFAudioPlayer.shared.configPlayer(audioPathURL: URL(fileURLWithPath: mod.wavFilePath))
|
|
|
+
|
|
|
let tt = currentAssetProgress - mod.startCMTime
|
|
|
BFLog(1, message: "record - tt: \(tt.seconds), curr:\(currentAssetProgress.seconds) \(needPlay) mod.wavFilePath\(mod.wavFilePath ?? "")")
|
|
|
if CMTimeCompare(tt, .zero) == 0 {
|
|
|
if needPlay {
|
|
|
- recordPlayer?.play()
|
|
|
+ BFAudioPlayer.shared.playOrPause()
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
- recordPlayer?.currentItem?.seek(to: tt, toleranceBefore: CMTime(value: 1, timescale: 1_000_000), toleranceAfter: CMTime(value: 1, timescale: 1_000_000)) { [weak recordPlayer] finishedre in
|
|
|
- if needPlay {
|
|
|
- recordPlayer?.play()
|
|
|
- }
|
|
|
- BFLog(message: "finishedre \(finishedre) 当前时间\(self.currentAssetProgress.seconds)")
|
|
|
- }
|
|
|
-
|
|
|
- NotificationCenter.default.addObserver(forName: .AVPlayerItemNewErrorLogEntry, object: recordPlayer?.currentItem, queue: .main) { notify in
|
|
|
- BFLog(message: "AVPlayerItemNewErrorLogEntry = \(notify)")
|
|
|
- }
|
|
|
- NotificationCenter.default.addObserver(forName: .AVPlayerItemFailedToPlayToEndTime, object: recordPlayer?.currentItem, queue: .main) { notify in
|
|
|
- BFLog(message: "AVPlayerItemFailedToPlayToEndTime = \(notify)")
|
|
|
- }
|
|
|
- NotificationCenter.default.addObserver(forName: .AVPlayerItemPlaybackStalled, object: recordPlayer?.currentItem, queue: .main) { notify in
|
|
|
- BFLog(message: "AVPlayerItemPlaybackStalled = \(notify)")
|
|
|
- }
|
|
|
- recordPlayer?.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: CMTimeScale(playerTimescale)), queue: .main) { [weak self] cmTime in
|
|
|
- let delta = CMTimeGetSeconds(cmTime)
|
|
|
-
|
|
|
- BFLog(message: "progress = \(delta)")
|
|
|
- }
|
|
|
-
|
|
|
- NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: recordPlayer?.currentItem, queue: .main) { [weak self] _ in
|
|
|
- guard let wself = self else {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- // 录制的视频如果不是播放过程当中 就不进行录音的播放了。
|
|
|
- let palyEndURlString = (wself.recordPlayer?.currentItem?.asset as? AVURLAsset)?.url.absoluteString ?? ""
|
|
|
- BFLog(message: "recordPlayer 播放完了:\(palyEndURlString) wself.avplayer.timeControlStatus \(wself.avplayer.timeControlStatus.rawValue) currentAssetProgress: \(wself.currentAssetProgress.seconds)")
|
|
|
- }
|
|
|
+ BFAudioPlayer.shared.setPlayingTime(tt.seconds)
|
|
|
+ BFAudioPlayer.shared.playOrPause()
|
|
|
+
|
|
|
} else {
|
|
|
BFLog(message: "没有找到即将播放的录制音频文件?\(currentAssetProgress.seconds)")
|
|
|
}
|
|
@@ -605,7 +579,7 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
|
|
|
BFLog(1, message: "endPlay:\(wself.currentAssetProgress.seconds), 总时长:\(wself.recordItem!.materialDuraion.seconds), currplayer:\(wself.avplayer.currentItem?.currentTime().seconds ?? 0)")
|
|
|
|
|
|
// 判断录音是否还在播放,如果在播放停止
|
|
|
- if wself.recordPlayer?.timeControlStatus == .playing {
|
|
|
+ if BFAudioPlayer.shared.player?.isPlaying ?? false {
|
|
|
wself.recordPlayer?.pause()
|
|
|
}
|
|
|
// 如果离结束大于0.7s,代表还有下一段视频
|
|
@@ -627,7 +601,7 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
|
|
|
override func pause() {
|
|
|
dispatchWorkItemIsCancel = true
|
|
|
avplayer.pause()
|
|
|
- recordPlayer?.pause()
|
|
|
+ BFAudioPlayer.shared.pause()
|
|
|
|
|
|
timerr?.invalidate()
|
|
|
timerr = nil
|
|
@@ -734,6 +708,7 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
|
|
|
|
|
|
checkCurrentPlayStatus()
|
|
|
prepareToPlayNext()
|
|
|
+ playRecordVoice()
|
|
|
}
|
|
|
|
|
|
func timerForRecord(currTime _: CMTime) {
|