|
@@ -362,13 +362,7 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
|
|
|
avplayer.replaceCurrentItem(with: nil)
|
|
|
}
|
|
|
|
|
|
- if avplayer.currentItem != nil {
|
|
|
- avplayer.play()
|
|
|
-// recordPlayer?.play()
|
|
|
- playRecordVoice()
|
|
|
- }else{
|
|
|
- prepareToPlayNext()
|
|
|
- }
|
|
|
+ prepareToPlayNext()
|
|
|
|
|
|
|
|
|
}
|
|
@@ -381,6 +375,12 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
|
|
|
recordPlayer?.replaceCurrentItem(with: AVPlayerItem(url: URL(fileURLWithPath: mod.wavFilePath)))
|
|
|
let tt = currentAssetProgress - mod.startCMTime
|
|
|
BFLog(1, message: "record - tt: \(tt.seconds), curr:\(currentAssetProgress.seconds)")
|
|
|
+ if CMTimeCompare(tt, .zero) == 0 {
|
|
|
+ if needPlay{
|
|
|
+ recordPlayer?.play()
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
recordPlayer?.currentItem?.seek(to: tt, toleranceBefore: CMTime(value: 1, timescale: 1_000_000), toleranceAfter: CMTime(value: 1, timescale: 1_000_000)) { [weak recordPlayer] _ in
|
|
|
if needPlay{
|
|
|
recordPlayer?.play()
|
|
@@ -389,21 +389,33 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func prepareToPlayNext(_ tt:CMTime = .zero, needPlay:Bool = true){
|
|
|
+ func findNextModel() {
|
|
|
+ if let mod = recordItem?.videoStickers.sorted(by: { m1, m2 in
|
|
|
+ m1.timelineCMIn.seconds < m2.timelineCMIn.seconds
|
|
|
+ }).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
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func prepareToPlayNext(needPlay:Bool = true){
|
|
|
if let mod = recordItem?.videoStickers.sorted(by: { m1, m2 in
|
|
|
m1.timelineCMIn.seconds < m2.timelineCMIn.seconds
|
|
|
}).first(where: { mod in
|
|
|
CMTimeCompare(mod.timelineCMIn, currentAssetProgress + CMTime(seconds: 0.033, preferredTimescale: 1000)) <= 0 && CMTimeCompare((currentAssetProgress + CMTime(seconds: 0.033, preferredTimescale: 1000)), mod.timelineCMOut) < 0
|
|
|
}){
|
|
|
currPlayTime = mod.timelineCMIn
|
|
|
- locationTo(time: mod.timelineCMIn)
|
|
|
+ locationTo(time: currentAssetProgress)
|
|
|
avplayerReplaceItem(newItem: AVPlayerItem(url: URL(fileURLWithPath: mod.locationPath)))
|
|
|
+
|
|
|
+ let tt = currentAssetProgress - currPlayTime
|
|
|
+ BFLog(1, message: "asset - tt: \(tt.seconds), curr:\(currentAssetProgress.seconds)")
|
|
|
playerCoverIV.image = PQVideoSnapshotUtil.videoSnapshot(videoURL: URL(fileURLWithPath: mod.locationPath), time: tt.seconds)
|
|
|
|
|
|
- avplayer.currentItem?.seek(to: tt, toleranceBefore: CMTime(value: 1, timescale: 1_000_000), toleranceAfter: CMTime(value: 1, timescale: 1_000_000), completionHandler: {[weak self, weak avplayer] _ in
|
|
|
-
|
|
|
- guard let wself = self else { return }
|
|
|
-
|
|
|
+ avplayer.currentItem?.seek(to: tt, toleranceBefore: CMTime(value: 1, timescale: 1_000_000), toleranceAfter: CMTime(value: 1, timescale: 1_000_000), completionHandler: {[weak avplayer] _ in
|
|
|
+
|
|
|
if needPlay {
|
|
|
avplayer?.play()
|
|
|
}
|
|
@@ -433,9 +445,12 @@ 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{
|
|
|
+ wself.recordPlayer?.pause()
|
|
|
+ }
|
|
|
// 如果离结束大于0.7s,代表还有下一段视频
|
|
|
if ((wself.recordItem?.materialDuraion ?? .zero) - wself.currentAssetProgress).seconds > 0.7 {
|
|
|
+ wself.findNextModel()
|
|
|
wself.prepareToPlayNext()
|
|
|
}else{
|
|
|
// 播放到末尾了
|
|
@@ -459,15 +474,14 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
|
|
|
if let mod = recordItem?.videoStickers.first(where: { m in
|
|
|
CMTimeCompare(m.timelineCMIn, currentAssetProgress) <= 0 && CMTimeCompare(m.timelineCMOut, currentAssetProgress) > 0
|
|
|
}){
|
|
|
+ currPlayTime = mod.timelineCMIn
|
|
|
let tt = currentAssetProgress - currPlayTime
|
|
|
|
|
|
avplayerReplaceItem(newItem: AVPlayerItem(url: URL(fileURLWithPath: mod.locationPath)))
|
|
|
- currPlayTime = mod.timelineCMIn
|
|
|
playerCoverIV.isHidden = false
|
|
|
playerCoverIV.image = PQVideoSnapshotUtil.videoSnapshot(videoURL: URL(fileURLWithPath: mod.locationPath), time: tt.seconds)
|
|
|
|
|
|
- BFLog(1, message: "asset - tt: \(tt.seconds), curr:\(currentAssetProgress.seconds)")
|
|
|
- prepareToPlayNext(tt, needPlay: false)
|
|
|
+ prepareToPlayNext(needPlay: false)
|
|
|
}else{
|
|
|
playerCoverIV.isHidden = true
|
|
|
}
|
|
@@ -485,7 +499,7 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
|
|
|
|
|
|
cameraProgressV?.isHidden = false
|
|
|
|
|
|
- prepareToPlayNext(currentAssetProgress, needPlay: false)
|
|
|
+ prepareToPlayNext(needPlay: false)
|
|
|
avplayerReplaceItem(newItem: nil)
|
|
|
|
|
|
if currentAssetProgress == .zero {
|