|
@@ -28,6 +28,14 @@ class BFRecordScreenBaseManager : NSObject{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //播放背景音乐
|
|
|
+ lazy var playBGMPlayer : BFAudioPlayer = {
|
|
|
+ let player = BFAudioPlayer.init()
|
|
|
+ player.delegate = self
|
|
|
+ return player
|
|
|
+
|
|
|
+ }()
|
|
|
+
|
|
|
var playView : GPUImageView?
|
|
|
var filter = GPUImageFilter()
|
|
|
|
|
@@ -39,6 +47,7 @@ class BFRecordScreenBaseManager : NSObject{
|
|
|
}
|
|
|
|
|
|
var recording = false
|
|
|
+ //录制的音频或变音是否正在播放
|
|
|
var isPlaying = false
|
|
|
// MARK: -
|
|
|
func resetEnv(){
|
|
@@ -60,10 +69,15 @@ class BFRecordScreenBaseManager : NSObject{
|
|
|
|
|
|
func play(){
|
|
|
|
|
|
+ playBGM()
|
|
|
}
|
|
|
|
|
|
func pause(){
|
|
|
+
|
|
|
+ playBGMPlayer.pause()
|
|
|
|
|
|
+ // add by ak 暂停时 isPlaying 设置为 false
|
|
|
+ isPlaying = false
|
|
|
}
|
|
|
|
|
|
func changeRecordMaterail(){
|
|
@@ -112,18 +126,69 @@ class BFRecordScreenBaseManager : NSObject{
|
|
|
wself.recordPlayer?.play()
|
|
|
|
|
|
})
|
|
|
- }else{
|
|
|
- BFLog(message: "this is run isPlaying\(isPlaying) su:\(su)")
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
|
|
|
- BFLog(message: "voice is nill");
|
|
|
+ BFLog(message: "voice is nill currentAssetProgress is\(currentAssetProgress)");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /// 播放背景音乐方法
|
|
|
+ func playBGM(){
|
|
|
+ if(dele?.bgmModel != nil){
|
|
|
+
|
|
|
+ if(dele?.bgmModel?.endCMTime.seconds == 0){
|
|
|
+ BFLog(message: "当前素材的结束时间有问题播放不成功.");
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ playBGMPlayer.configPlayer(audioPathURL: URL(fileURLWithPath: dele?.bgmModel?.wavFilePath ?? ""))
|
|
|
+ //原背景音乐可使用时长
|
|
|
+ let bgmSeconds = ((dele?.bgmModel?.endCMTime ?? .zero) - (dele?.bgmModel?.startCMTime ?? .zero)).seconds
|
|
|
+ //余数
|
|
|
+ let step = currentAssetProgress.seconds.truncatingRemainder(dividingBy: bgmSeconds)
|
|
|
+ var seekTime = (dele?.bgmModel?.startCMTime ?? .zero).seconds + step
|
|
|
+ if(step == 0){//当时间小于音乐时长
|
|
|
+ seekTime += currentAssetProgress.seconds
|
|
|
+ }
|
|
|
+ BFLog(message: "seekTime is: \(seekTime) step is:\(step)")
|
|
|
+
|
|
|
+ playBGMPlayer.seekTime(seekTime)
|
|
|
+ playBGMPlayer.play()
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
deinit {
|
|
|
clean()
|
|
|
BFLog(1, message: "\(self) release")
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+extension BFRecordScreenBaseManager: BFAudioPlayerDelegate{
|
|
|
+
|
|
|
+ // 播放完成
|
|
|
+ func audioPlayerDidFinish(audioPlayer:BFAudioPlayer){
|
|
|
+ BFLog(message: "audioPlayerDidFinish")
|
|
|
+ //背景音乐播放完成后,素材还在播放,再次调用播放背景音乐,开始播放的起点在playBGM已处理
|
|
|
+ if(isPlaying){
|
|
|
+ playBGM()
|
|
|
+ BFLog(message: "进行下一次播放背景音乐")
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 播放开始
|
|
|
+ func audioPlayerStart(audioPlayer:BFAudioPlayer){
|
|
|
+
|
|
|
+ }
|
|
|
+ // 播放进度
|
|
|
+ func playProgress(audioPlayer:BFAudioPlayer,currentTime: TimeInterval, progress: Double){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|