|
@@ -268,8 +268,9 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
var currenStartPlayTime: CMTime = .zero
|
|
|
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 playView: GPUImageView? // 视频展示视图
|
|
@@ -664,10 +665,10 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
wself.bgmModel?.volume = Int(musicVolume)
|
|
|
wself.originalVolume = originalVolume / 100.0
|
|
|
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
|
|
@@ -1732,6 +1733,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
@objc func endRecord() {
|
|
|
// 存储录音
|
|
|
+
|
|
|
if !isRecording {
|
|
|
return
|
|
|
}
|
|
@@ -2138,20 +2140,26 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
|
|
|
// 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) {
|
|
|
|
|
|
//add by ak 使用的音频数据
|
|
|
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)")
|
|
|
|
|
|
if currentPlayRecordIndex == -3 { // 刚录音完,不需要播放
|
|
@@ -2172,7 +2180,6 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
return
|
|
|
}
|
|
|
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 {
|
|
|
let newItem = AVPlayerItem(url: URL(fileURLWithPath: recordedAudio.wavFilePath))
|
|
@@ -2198,20 +2205,20 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
wself.hadPrepareToPlayRecord = false
|
|
|
wself.currentPlayRecordIndex = -1
|
|
|
-// wself.recordPlayer.volume = 0
|
|
|
-// wself.assetPlayer.volume = wself.musicVolume
|
|
|
+
|
|
|
+ wself.assetPlayer.volume = wself.originalVolume
|
|
|
+
|
|
|
BFLog(3, message: "播放结束")
|
|
|
didPlayToEndTime((shouldPlayRecordIndex, recordedAudio), newItem)
|
|
|
}
|
|
|
// recordPlayer.removeTimeObserver(recordPlayerTimeObserver as Any)
|
|
|
// recordPlayerTimeObserver?.invalidate()
|
|
|
//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 {
|
|
|
BFLog(message: "重新更新开始播放进度\(#function)-\(wself.currenStartPlayTime.seconds)")
|
|
|
wself.currenStartPlayTime = time
|
|
@@ -2219,9 +2226,6 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
let progressTime = CMTime(seconds: CMTimeGetSeconds(time) - CMTimeGetSeconds(wself.currenStartPlayTime), preferredTimescale: 1000)
|
|
|
BFLog(message: "progressTime进度\(#function)-\(progressTime.seconds)")
|
|
|
periodicTimeObserver(progressTime, newItem)
|
|
|
-// if (rPlay.currentItem?.currentTime().seconds ?? 0) > (rPlay.currentItem?.duration.seconds ?? 0) - 0.1 {
|
|
|
-// didPlayToEndTime((shouldPlayRecordIndex, recordedAudio), newItem)
|
|
|
-// }
|
|
|
} as? NSKeyValueObservation
|
|
|
}
|
|
|
if currMediaType == .Video {
|
|
@@ -2323,7 +2327,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
BFLog(1, message: "开始播放 \(currentAssetProgress.seconds)")
|
|
|
recorderManager?.voiceModel = nil
|
|
|
events.append(WithDrawModel(type: 1, timestamp: currentAssetProgress, recordItem: rscurrentManager.recordItem!))
|
|
|
-
|
|
|
+
|
|
|
itemModels[currItemModelIndex].titleStickers.sort { m1, m2 in
|
|
|
CMTimeCompare(m1.timelineIn, m2.timelineIn) < 0
|
|
|
}
|
|
@@ -2350,9 +2354,19 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
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()
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public func pause() {
|
|
@@ -2368,7 +2382,10 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
// 暂停状态
|
|
|
updatePlayBtnStatus()
|
|
|
+
|
|
|
+ bgmPlayer.pause()
|
|
|
rscurrentManager.pause()
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public func fetchMaterial(_ phAsset:[PHAsset]) {
|
|
@@ -2517,7 +2534,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
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())
|
|
|
let su = !wself.isDragingProgressSlder || wself.isRecording || wself.isNormalPlaying
|
|
|
if su { // 不拖动,正常播放和录音时更新进度条
|
|
@@ -2593,7 +2610,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
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())
|
|
|
}
|
|
|
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?) {
|
|
|
bgmModel = music
|
|
|
-
|
|
|
+ bgmPlayer.replaceCurrentItem(musicPath: bgmModel?.musicPath)
|
|
|
+
|
|
|
if let model = music {
|
|
|
|
|
|
BFEventTrackAdaptor.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_musicChangerButton, pageSource: .sp_speekPage,extParams: ["musicID":bgmModel?.musicId ?? ""],commonParams: commonParams())
|