|
@@ -45,14 +45,13 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
|
|
|
|
|
|
var startTime = Date()
|
|
var startTime = Date()
|
|
var videoModel = PQEditVisionTrackMaterialsModel()
|
|
var videoModel = PQEditVisionTrackMaterialsModel()
|
|
-
|
|
|
|
|
|
+ var playingVoiceMode : PQVoiceModel?
|
|
// 用于打开摄像头初始流程
|
|
// 用于打开摄像头初始流程
|
|
static var initOpenCamera: Bool = true
|
|
static var initOpenCamera: Bool = true
|
|
|
|
|
|
// timer循环每次录制增长的时长
|
|
// timer循环每次录制增长的时长
|
|
var increaseTime: CMTime = .zero
|
|
var increaseTime: CMTime = .zero
|
|
|
|
|
|
- var currPlayTime: CMTime = .zero
|
|
|
|
fileprivate var timerr: Timer?
|
|
fileprivate var timerr: Timer?
|
|
|
|
|
|
var writerlock = false
|
|
var writerlock = false
|
|
@@ -77,35 +76,13 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
|
|
}()
|
|
}()
|
|
|
|
|
|
var groupCount = 0
|
|
var groupCount = 0
|
|
-
|
|
|
|
- var avplayerTimeObserver: NSKeyValueObservation?
|
|
|
|
|
|
|
|
|
|
+ // 录音文件是否正在播放
|
|
var audioPlayerIsPlaying:Bool = false
|
|
var audioPlayerIsPlaying:Bool = false
|
|
|
|
|
|
lazy var avplayer: AVPlayer = {
|
|
lazy var avplayer: AVPlayer = {
|
|
let p = AVPlayer(playerItem: nil)
|
|
let p = AVPlayer(playerItem: nil)
|
|
- avplayerTimeObserver = p.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 100), queue: DispatchQueue.global(), using: { [weak self] currTime in
|
|
|
|
-
|
|
|
|
- guard let wself = self else { return }
|
|
|
|
-
|
|
|
|
- // 拖动的跳跃,不要修改时间点
|
|
|
|
- if wself.dele?.isNormalPlaying ?? false {
|
|
|
|
-// wself.currentAssetProgress = CMTime(seconds: (currTime + wself.currPlayTime).seconds, preferredTimescale: 1000)
|
|
|
|
-
|
|
|
|
- BFLog(message: "当前播放器状态: \(wself.avplayer.timeControlStatus.rawValue) \(wself.currentAssetProgress.seconds)")
|
|
|
|
- }
|
|
|
|
-// BFLog(1, message: "拖动 currTime: \(currTime.seconds)")
|
|
|
|
- DispatchQueue.main.async { [weak self] in
|
|
|
|
- guard let wself = self else { return }
|
|
|
|
- // add by ak 播放状态才进行刷新 UI
|
|
|
|
- if wself.avplayer.timeControlStatus == .playing {
|
|
|
|
- wself.dele?.updateSubtitle(time: wself.currentAssetProgress)
|
|
|
|
- wself.locationTo(time: wself.currentAssetProgress)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }) as? NSKeyValueObservation
|
|
|
|
-
|
|
|
|
|
|
+
|
|
return p
|
|
return p
|
|
}()
|
|
}()
|
|
|
|
|
|
@@ -129,13 +106,6 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
|
|
|
|
|
|
// MARK: 重放
|
|
// MARK: 重放
|
|
|
|
|
|
- deinit {
|
|
|
|
- if avplayerTimeObserver != nil {
|
|
|
|
- avplayer.removeTimeObserver(avplayerTimeObserver as Any)
|
|
|
|
- avplayerTimeObserver?.invalidate()
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
override func resetEnv() {
|
|
override func resetEnv() {
|
|
guard let camera = camera else {
|
|
guard let camera = camera else {
|
|
cShowHUB(superView: nil, msg: "option_fail_camera".BFLocale)
|
|
cShowHUB(superView: nil, msg: "option_fail_camera".BFLocale)
|
|
@@ -449,7 +419,6 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
|
|
// 100ms以内的重头开始播放
|
|
// 100ms以内的重头开始播放
|
|
if (recordItem?.materialDuraion.seconds)! - currentAssetProgress.seconds < 0.1 {
|
|
if (recordItem?.materialDuraion.seconds)! - currentAssetProgress.seconds < 0.1 {
|
|
currentAssetProgress = .zero
|
|
currentAssetProgress = .zero
|
|
- currPlayTime = .zero
|
|
|
|
locationTo(time: currentAssetProgress)
|
|
locationTo(time: currentAssetProgress)
|
|
avplayer.replaceCurrentItem(with: nil)
|
|
avplayer.replaceCurrentItem(with: nil)
|
|
}
|
|
}
|
|
@@ -484,19 +453,27 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
|
|
BFLog(message: "找到音频开始时间:\(mod.startCMTime.seconds)结束 \(mod.endCMTime.seconds) currentAssetProgress is \(currentAssetProgress.seconds)")
|
|
BFLog(message: "找到音频开始时间:\(mod.startCMTime.seconds)结束 \(mod.endCMTime.seconds) currentAssetProgress is \(currentAssetProgress.seconds)")
|
|
|
|
|
|
// 当前播放的文件
|
|
// 当前播放的文件
|
|
|
|
+ if playingVoiceMode == mod {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ playingVoiceMode = mod
|
|
|
|
|
|
let cureentPalyURlString = BFAudioPlayer.shared.currentAudioPathURL?.absoluteString ?? ""
|
|
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 || (BFAudioPlayer.shared.player?.isPlaying ?? false){
|
|
BFLog(2, message: "命中的和播放的文件路径一样? wavFilePath:\(mod.wavFilePath ?? "")")
|
|
BFLog(2, message: "命中的和播放的文件路径一样? wavFilePath:\(mod.wavFilePath ?? "")")
|
|
|
|
+ if !(BFAudioPlayer.shared.player?.isPlaying ?? false) {
|
|
|
|
+ audioPlayerIsPlaying = true
|
|
|
|
+ BFAudioPlayer.shared.playOrPause()
|
|
|
|
+ }
|
|
return
|
|
return
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
BFAudioPlayer.shared.delegate = self
|
|
BFAudioPlayer.shared.delegate = self
|
|
BFAudioPlayer.shared.configPlayer(audioPathURL: URL(fileURLWithPath: mod.wavFilePath))
|
|
BFAudioPlayer.shared.configPlayer(audioPathURL: URL(fileURLWithPath: mod.wavFilePath))
|
|
BFAudioPlayer.shared.player?.rate = 2.0
|
|
BFAudioPlayer.shared.player?.rate = 2.0
|
|
|
|
|
|
let tt = currentAssetProgress - mod.startCMTime
|
|
let tt = currentAssetProgress - mod.startCMTime
|
|
- BFLog(1, message: "record - tt: \(tt.seconds), curr:\(currentAssetProgress.seconds) \(needPlay) mod.wavFilePath\(mod.wavFilePath ?? "")")
|
|
|
|
|
|
+ BFLog(1, message: "record - tt: \(tt.seconds), curr:\(currentAssetProgress.seconds) \(needPlay)")
|
|
if CMTimeCompare(tt, .zero) == 0 {
|
|
if CMTimeCompare(tt, .zero) == 0 {
|
|
if needPlay {
|
|
if needPlay {
|
|
audioPlayerIsPlaying = true
|
|
audioPlayerIsPlaying = true
|
|
@@ -513,16 +490,6 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- func findNextModel() {
|
|
|
|
- if let mod = recordItem?.videoStickers.first(where: { mod in
|
|
|
|
- CMTimeCompare(mod.timelineCMIn, currentAssetProgress + CMTime(seconds: 0.6, preferredTimescale: 1000)) <= 0 && CMTimeCompare((currentAssetProgress + CMTime(seconds: 0.6, preferredTimescale: 1000)), mod.timelineCMOut) < 0
|
|
|
|
- }) {
|
|
|
|
- currPlayTime = mod.timelineCMIn
|
|
|
|
- currentAssetProgress = currPlayTime
|
|
|
|
- BFLog(1, message: "视频查找下一个:\(currentAssetProgress.seconds)")
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
func prepareToPlayNext(needPlay: Bool = true) {
|
|
func prepareToPlayNext(needPlay: Bool = true) {
|
|
|
|
|
|
if let mod = recordItem?.videoStickers.first(where: { mode in
|
|
if let mod = recordItem?.videoStickers.first(where: { mode in
|
|
@@ -534,15 +501,18 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
|
|
if !su {
|
|
if !su {
|
|
if avplayer.timeControlStatus == .paused {
|
|
if avplayer.timeControlStatus == .paused {
|
|
avplayer.play()
|
|
avplayer.play()
|
|
|
|
+ setCoverImage(currentAssetProgress)
|
|
|
|
+
|
|
}
|
|
}
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- currPlayTime = mod.timelineCMIn
|
|
|
|
- locationTo(time: currentAssetProgress)
|
|
|
|
|
|
+ setCoverImage(currentAssetProgress)
|
|
|
|
+
|
|
|
|
+// locationTo(time: currentAssetProgress)
|
|
avplayerReplaceItem(newItem: AVPlayerItem(url: URL(fileURLWithPath: mod.locationPath)))
|
|
avplayerReplaceItem(newItem: AVPlayerItem(url: URL(fileURLWithPath: mod.locationPath)))
|
|
BFLog(1, message: "当前:\(currentAssetProgress.seconds), mod:\(mod.timelineCMIn.seconds) ~ \(mod.timelineCMOut.seconds)")
|
|
BFLog(1, message: "当前:\(currentAssetProgress.seconds), mod:\(mod.timelineCMIn.seconds) ~ \(mod.timelineCMOut.seconds)")
|
|
- let tt = currentAssetProgress - currPlayTime
|
|
|
|
|
|
+ let tt = currentAssetProgress - mod.timelineCMIn
|
|
BFLog(1, message: "asset - tt: \(tt.seconds), curr:\(currentAssetProgress.seconds)")
|
|
BFLog(1, message: "asset - tt: \(tt.seconds), curr:\(currentAssetProgress.seconds)")
|
|
|
|
|
|
if CMTimeCompare(tt, (avplayer.currentItem?.duration ?? .zero)) == 0 {
|
|
if CMTimeCompare(tt, (avplayer.currentItem?.duration ?? .zero)) == 0 {
|
|
@@ -591,7 +561,7 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
|
|
// 如果离结束大于0.7s,代表还有下一段视频
|
|
// 如果离结束大于0.7s,代表还有下一段视频
|
|
if ((wself.recordItem?.materialDuraion ?? .zero) - wself.currentAssetProgress).seconds > 0.7 {
|
|
if ((wself.recordItem?.materialDuraion ?? .zero) - wself.currentAssetProgress).seconds > 0.7 {
|
|
// wself.findNextModel()
|
|
// wself.findNextModel()
|
|
- wself.setCoverImage(wself.currentAssetProgress)
|
|
|
|
|
|
+// wself.setCoverImage(wself.currentAssetProgress)
|
|
|
|
|
|
// wself.prepareToPlayNext()
|
|
// wself.prepareToPlayNext()
|
|
} else {
|
|
} else {
|
|
@@ -609,7 +579,11 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
|
|
avplayer.pause()
|
|
avplayer.pause()
|
|
|
|
|
|
BFAudioPlayer.shared.pause()
|
|
BFAudioPlayer.shared.pause()
|
|
|
|
+
|
|
audioPlayerIsPlaying = false
|
|
audioPlayerIsPlaying = false
|
|
|
|
+
|
|
|
|
+ playingVoiceMode = nil
|
|
|
|
+
|
|
timerr?.invalidate()
|
|
timerr?.invalidate()
|
|
timerr = nil
|
|
timerr = nil
|
|
|
|
|
|
@@ -625,10 +599,10 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
|
|
CMTimeCompare(m.timelineCMIn, currentAssetProgress) <= 0 && CMTimeCompare(m.timelineCMOut, currentAssetProgress) > 0
|
|
CMTimeCompare(m.timelineCMIn, currentAssetProgress) <= 0 && CMTimeCompare(m.timelineCMOut, currentAssetProgress) > 0
|
|
}), (CMTimeCompare(currentAssetProgress, (recordItem?.materialDuraion ?? .zero)) < 0) {
|
|
}), (CMTimeCompare(currentAssetProgress, (recordItem?.materialDuraion ?? .zero)) < 0) {
|
|
BFLog(1, message: "drag end:\(currentAssetProgress.seconds), mod:\(mod.timelineCMIn)")
|
|
BFLog(1, message: "drag end:\(currentAssetProgress.seconds), mod:\(mod.timelineCMIn)")
|
|
- currPlayTime = mod.timelineCMIn
|
|
|
|
- playerCoverIV.image = getThumbImageAtTime(urlAsset: AVURLAsset(url: URL(fileURLWithPath: mod.locationPath)), time: currentAssetProgress - currPlayTime)
|
|
|
|
- playerCoverIV.isHidden = false
|
|
|
|
|
|
|
|
|
|
+ playerCoverIV.image = getThumbImageAtTime(urlAsset: AVURLAsset(url: URL(fileURLWithPath: mod.locationPath)), time: currentAssetProgress - mod.timelineCMIn)
|
|
|
|
+ playerCoverIV.isHidden = false
|
|
|
|
+
|
|
avplayerReplaceItem(newItem: AVPlayerItem(url: URL(fileURLWithPath: mod.locationPath)))
|
|
avplayerReplaceItem(newItem: AVPlayerItem(url: URL(fileURLWithPath: mod.locationPath)))
|
|
|
|
|
|
// prepareToPlayNext(needPlay: false)
|
|
// prepareToPlayNext(needPlay: false)
|
|
@@ -757,7 +731,7 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
|
|
cameraProgressV?.progressView.contentOffset = p
|
|
cameraProgressV?.progressView.contentOffset = p
|
|
}
|
|
}
|
|
|
|
|
|
- /// 更新录音进度
|
|
|
|
|
|
+ /// 录制时更新录音进度
|
|
/// - Parameter progress: 当前的进度
|
|
/// - Parameter progress: 当前的进度
|
|
func updateUI(progress: CMTime) {
|
|
func updateUI(progress: CMTime) {
|
|
DispatchQueue.main.async { [weak self] in
|
|
DispatchQueue.main.async { [weak self] in
|