|
@@ -522,6 +522,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
self?.recordBtn.isHidden = (self?.itemModels[self?.currItemModelIndex ?? 0].mediaType == .IMAGE && (self?.isEndPlay ?? false)) ? false : (self?.isEndPlay ?? false)
|
|
|
}
|
|
|
sself.currentPlayRecordIndex = -3 // 刚录音完,不需要播放录音
|
|
|
+ BFLog(3, message: "重置播放index = \(sself.currentPlayRecordIndex)")
|
|
|
// 重置录制开始时间
|
|
|
sself.recordStartTime = 0
|
|
|
}
|
|
@@ -929,6 +930,8 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
// 录制中不显示播放按钮
|
|
|
(collectionView.cellForItem(at: IndexPath(item: currItemModelIndex, section: 0)) as? BFImageCoverViewCell)?.playBtn.isSelected = true
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@objc func endRecord() {
|
|
@@ -1032,6 +1035,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
isDragingProgressSlder = false
|
|
|
currentPlayRecordIndex = -1
|
|
|
+ BFLog(3, message: "重置播放index = \(currentPlayRecordIndex)")
|
|
|
hadPrepareToPlayRecord = false
|
|
|
progressThumV.progress = jumpTime
|
|
|
|
|
@@ -1078,6 +1082,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
changeProgress(progress: sender.value)
|
|
|
isDragingProgressSlder = false
|
|
|
currentPlayRecordIndex = -1
|
|
|
+ BFLog(3, message: "重置播放index = \(currentPlayRecordIndex)")
|
|
|
hadPrepareToPlayRecord = false
|
|
|
}
|
|
|
|
|
@@ -1248,9 +1253,12 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
avplayerTimeObserver = recordPlayer?.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 1000), queue: DispatchQueue.global()) { [weak self] time in
|
|
|
BFLog(3, message: "当前播放---\(time),\(time.seconds)")
|
|
|
if CMTimeGetSeconds(self?.currenStartPlayTime ?? CMTime.zero) <= 0 {
|
|
|
+ BFLog(message: "重新更新开始播放进度\(#function)-\((self?.currenStartPlayTime.seconds ?? 0))")
|
|
|
self?.currenStartPlayTime = time
|
|
|
}
|
|
|
- periodicTimeObserver(CMTime(seconds: CMTimeGetSeconds(time) - CMTimeGetSeconds(self?.currenStartPlayTime ?? CMTime.zero), preferredTimescale: 1000), newItem)
|
|
|
+ let progressTime = CMTime(seconds: CMTimeGetSeconds(time) - CMTimeGetSeconds(self?.currenStartPlayTime ?? CMTime.zero), preferredTimescale: 1000)
|
|
|
+ BFLog(message: "progressTime进度\(#function)-\(progressTime.seconds)")
|
|
|
+ periodicTimeObserver(progressTime, newItem)
|
|
|
} as? NSKeyValueObservation
|
|
|
}
|
|
|
|
|
@@ -1291,7 +1299,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
currentPlayRecordIndex = shouldPlayRecordIndex
|
|
|
hadPrepareToPlayRecord = true
|
|
|
- BFLog(1, message: "录音开始播放2, \(second), \(CMTimeGetSeconds(recordPlayer?.currentItem?.duration ?? .zero))")
|
|
|
+ BFLog(1, message: "录音开始播放2, \(second), \(CMTimeGetSeconds(recordPlayer?.currentItem?.duration ?? .zero)),index = \(currentPlayRecordIndex)")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1307,6 +1315,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
assetPlayer?.seek(to: CMTime.zero)
|
|
|
progressThumV.progress = 0
|
|
|
currentPlayRecordIndex = -1
|
|
|
+ BFLog(3, message: "重置播放index = \(currentPlayRecordIndex)")
|
|
|
if itemModels[currItemModelIndex].mediaType == .VIDEO {
|
|
|
recordBtn.isHidden = false
|
|
|
}
|
|
@@ -1321,7 +1330,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
assetPlayer?.play()
|
|
|
} else {
|
|
|
// 处理图片音频播放
|
|
|
- imageRecordPlay()
|
|
|
+ playRecord(time: currentAssetProgress)
|
|
|
}
|
|
|
|
|
|
deleteRecordBtn.isHidden = true
|
|
@@ -1335,7 +1344,8 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
func pause() {
|
|
|
BFLog(1, message: "暂停播放")
|
|
|
isNormalPlaying = false
|
|
|
-
|
|
|
+ avplayerTimeObserver?.invalidate()
|
|
|
+ avplayerTimeObserver = nil
|
|
|
subtitleBtn.isHidden = false
|
|
|
soundSettingBtn.isHidden = false
|
|
|
withDrawBtn.isHidden = false
|
|
@@ -1423,14 +1433,9 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
avplayerTimeObserver = assetPlayer?.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 1000), queue: DispatchQueue.global()) { [weak self] time in
|
|
|
// 进度监控
|
|
|
self?.periodicTimeObserver(item: item, time: time)
|
|
|
-
|
|
|
if self?.isNormalPlaying ?? false {
|
|
|
- // 播放对应的录音音频
|
|
|
- self?.playRecord(at: time, periodicTimeObserver: { currentT, currentItem in
|
|
|
- BFLog(message: "播放一段进度:\(currentT),\(currentItem)")
|
|
|
- }, didPlayToEndTime: { recordInfo, _ in
|
|
|
- BFLog(message: "播放一段结束:\(recordInfo?.1.endTime ?? 0)")
|
|
|
- }, playFailed: { _, _ in })
|
|
|
+ // 播放录音
|
|
|
+ self?.playRecord(time: time)
|
|
|
}
|
|
|
} as? NSKeyValueObservation
|
|
|
}
|
|
@@ -1461,6 +1466,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
currentAssetProgress = CMTime(seconds: time.seconds, preferredTimescale: 1000)
|
|
|
BFLog(1, message: "curr:\(CMTimeGetSeconds(currentAssetProgress))")
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
+ BFLog(message: "更新录音进度\(#function)-\((self?.currentAssetProgress.seconds ?? 0))")
|
|
|
self?.progreddL.text = String(format: "%@", CMTimeGetSeconds(time).formatDurationToHMS())
|
|
|
let su = !(self?.isDragingProgressSlder ?? false) || (self?.isRecording ?? false) || (self?.isNormalPlaying ?? false)
|
|
|
if su {
|
|
@@ -1512,6 +1518,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
if let duration = assetPlayer?.currentItem?.duration {
|
|
|
currentAssetProgress = CMTime(value: CMTimeValue(newProgress * Float(CMTimeGetSeconds(duration)) * 1000), timescale: 1000)
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
+ BFLog(message: "更新录音进度\(#function)-\((self?.currentAssetProgress.seconds ?? 0))")
|
|
|
self!.progreddL.text = String(format: "%@", CMTimeGetSeconds(self!.currentAssetProgress).formatDurationToHMS())
|
|
|
}
|
|
|
assetPlayer!.seek(to: currentAssetProgress, toleranceBefore: CMTime(value: 1, timescale: 1_000_000), toleranceAfter: CMTime(value: 1, timescale: 1_000_000)) { _ in
|
|
@@ -1520,6 +1527,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
} else {
|
|
|
currentAssetProgress = isBack ? CMTime(value: CMTimeValue(progress * 1000), timescale: 1000) : CMTime(value: CMTimeValue(progress * Float(itemModels[currItemModelIndex].materialDuraion) * 1000), timescale: 1000)
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
+ BFLog(message: "更新录音进度\(#function)-\((self?.currentAssetProgress.seconds ?? 0))")
|
|
|
self?.progreddL.text = String(format: "%@", CMTimeGetSeconds(self!.currentAssetProgress).formatDurationToHMS())
|
|
|
}
|
|
|
BFLog(message: "progress = \(progress),currentAssetProgress = \(currentAssetProgress.seconds),materialDuraion = \(itemModels[currItemModelIndex].materialDuraion)")
|
|
@@ -1574,6 +1582,7 @@ extension BFRecordScreenController: GPUImageMovieDelegate {
|
|
|
public func didCompletePlayingMovie() {
|
|
|
BFLog(1, message: "播放结束")
|
|
|
currentPlayRecordIndex = -1
|
|
|
+ BFLog(3, message: "重置播放index = \(currentPlayRecordIndex)")
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1701,8 +1710,11 @@ extension BFRecordScreenController: UICollectionViewDelegate, UICollectionViewDa
|
|
|
|
|
|
/// 处理图片素材
|
|
|
public extension BFRecordScreenController {
|
|
|
- /// 处理图片音频的播放
|
|
|
- func imageRecordPlay() {
|
|
|
+
|
|
|
+ /// 播放录音
|
|
|
+ /// - Parameter time: <#time description#>
|
|
|
+ func playRecord(time:CMTime) {
|
|
|
+ // 播放对应的录音音频
|
|
|
if itemModels[currItemModelIndex].mediaType == .IMAGE {
|
|
|
if itemModels[currItemModelIndex].materialDuraion <= 0 || currentAssetProgress.seconds >= itemModels[currItemModelIndex].materialDuraion {
|
|
|
(collectionView.cellForItem(at: IndexPath(item: currItemModelIndex, section: 0)) as? BFImageCoverViewCell)?.playBtn.isSelected = false
|
|
@@ -1712,11 +1724,15 @@ public extension BFRecordScreenController {
|
|
|
// 当开始播放时重置录音播放起始时间
|
|
|
recordStartPlayTime = currentAssetProgress
|
|
|
currenStartPlayTime = CMTime.zero
|
|
|
- playRecord(at: currentAssetProgress, periodicTimeObserver: { [weak self] currentT, currentItem in
|
|
|
- BFLog(1, message: "播放图片素材进度:\(currentT),\(currentItem)")
|
|
|
+ }
|
|
|
+ playRecord(at: time, periodicTimeObserver: { [weak self] currentT, currentItem in
|
|
|
+ BFLog(1, message: "播放录音进度:\(currentT),\(currentItem)")
|
|
|
+ if self?.itemModels[self?.currItemModelIndex ?? 0].mediaType == .IMAGE && (self?.isNormalPlaying ?? false) {
|
|
|
self?.imageRecordProgress(progress: CMTimeGetSeconds(currentT))
|
|
|
- }, didPlayToEndTime: { [weak self] recordInfo, currentItem in
|
|
|
- BFLog(message: "播放图片素材录音结束:\(String(describing: recordInfo?.1)),\(String(describing: currentItem))")
|
|
|
+ }
|
|
|
+ }, didPlayToEndTime: { [weak self] recordInfo, currentItem in
|
|
|
+ BFLog(message: "播放录音结束:\(String(describing: recordInfo?.1)),\(String(describing: currentItem))")
|
|
|
+ if self?.itemModels[self?.currItemModelIndex ?? 0].mediaType == .IMAGE {
|
|
|
if (self?.itemModels[self?.currItemModelIndex ?? 0].voiceStickers.count ?? 0) <= ((recordInfo?.0 ?? 0) + 1) || (recordInfo?.1.endTime ?? 0) >= (self?.itemModels[self?.currItemModelIndex ?? 0].voiceStickers.last?.endTime ?? 0) {
|
|
|
self?.isEndPlay = true
|
|
|
self?.pause()
|
|
@@ -1725,19 +1741,16 @@ public extension BFRecordScreenController {
|
|
|
self?.resetCurrentProgress()
|
|
|
// 录制播放结束后显示录制按钮
|
|
|
self?.recordBtn.isHidden = false
|
|
|
- // 跳转下一段
|
|
|
-// if (self?.currItemModelIndex ?? 0) < ((self?.itemModels.count ?? 0) - 1) {
|
|
|
-// self?.collectionView.setContentOffset(CGPoint(x: CGFloat((self?.currItemModelIndex ?? 0) + 1) * (self?.collectionView.frame.width ?? 0), y: 0), animated: true)
|
|
|
-// }
|
|
|
-
|
|
|
} else {
|
|
|
// 注:矫正进度--一段录音播放结束后当前指针应该到当前录音结束点
|
|
|
self?.currentAssetProgress = CMTime(seconds: self?.itemModels[self?.currItemModelIndex ?? 0].voiceStickers[(recordInfo?.0 ?? 0) + 1].startTime ?? 0, preferredTimescale: 1000)
|
|
|
- self?.imageRecordPlay()
|
|
|
+ self?.playRecord(time: self?.currentAssetProgress ?? CMTime.zero)
|
|
|
}
|
|
|
- }) { [weak self] _, _ in
|
|
|
+ }
|
|
|
+ }) { [weak self] _, _ in
|
|
|
+ if self?.itemModels[self?.currItemModelIndex ?? 0].mediaType == .IMAGE {
|
|
|
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3) {
|
|
|
- self?.imageRecordPlay()
|
|
|
+ self?.playRecord(time: self?.currentAssetProgress ?? CMTime.zero)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1760,6 +1773,7 @@ public extension BFRecordScreenController {
|
|
|
/// 重置进度
|
|
|
func resetCurrentProgress() {
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
+ BFLog(message: "更新录音进度\(#function)-\((self?.currentAssetProgress.seconds ?? 0))")
|
|
|
self?.progreddL.text = String(format: "%@", (self?.currentAssetProgress.seconds ?? 0).formatDurationToHMS())
|
|
|
self?.progressThumV.progress = (self?.currentAssetProgress.seconds ?? 0)
|
|
|
self?.updateSubtitle(time: self?.currentAssetProgress ?? CMTime.zero)
|