|
@@ -260,81 +260,6 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 录制失败 , 不足一秒时恢复上一次状态
|
|
|
- func revertLast(){
|
|
|
- videoModel.timelineCMOut = videoModel.timelineCMIn
|
|
|
- currentAssetProgress = videoModel.timelineCMOut
|
|
|
- recordItem?.thumbImgs.removeAll(where: { img in
|
|
|
- videoModel.thumImgs?.contains(img) ?? false
|
|
|
- })
|
|
|
- DispatchQueue.main.async {[weak self] in
|
|
|
- guard let wself = self else { return }
|
|
|
-
|
|
|
- wself.cameraProgressV?.collectionV.reloadData()
|
|
|
- }
|
|
|
- videoModel.thumImgs?.removeAll()
|
|
|
- recordItem?.videoStickers.removeLast()
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- // 使用avplayer进行播放视频和音频
|
|
|
- override func play() {
|
|
|
- guard let preView = playView else {
|
|
|
- return
|
|
|
- }
|
|
|
- if playerLayer.superlayer == nil {
|
|
|
- preView.layer.addSublayer(playerLayer)
|
|
|
- }
|
|
|
-
|
|
|
- camera?.pauseCapture()
|
|
|
-
|
|
|
- // 100ms以内的重头开始播放
|
|
|
- if (recordItem?.materialDuraion.seconds)! - currentAssetProgress.seconds < 0.1 {
|
|
|
- currentAssetProgress = .zero
|
|
|
- currPlayTime = .zero
|
|
|
- locationTo(time: currentAssetProgress)
|
|
|
- avplayer.replaceCurrentItem(with: nil)
|
|
|
- }
|
|
|
-
|
|
|
- if avplayer.currentItem != nil {
|
|
|
- avplayer.play()
|
|
|
- recordPlayer?.play()
|
|
|
- }else{
|
|
|
- prepareToPlayNext()
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- func playRecordVoice(_ tt:CMTime, needPlay:Bool = true){
|
|
|
- // 播放音频
|
|
|
- if let mod = recordItem?.voiceStickers.first(where: { m in
|
|
|
- CMTimeCompare(m.startCMTime, currentAssetProgress + CMTime(seconds: 0.033, preferredTimescale: 1000)) <= 0 && CMTimeCompare(m.endCMTime, currentAssetProgress) > 0
|
|
|
- }){
|
|
|
- recordPlayer?.replaceCurrentItem(with: AVPlayerItem(url: URL(fileURLWithPath: mod.wavFilePath)))
|
|
|
-
|
|
|
- BFLog(1, message: "record - tt: \(tt.seconds), curr:\(currentAssetProgress.seconds)")
|
|
|
- recordPlayer?.seek(to: tt, toleranceBefore: CMTime(seconds: 1, preferredTimescale: 1000), toleranceAfter: CMTime(seconds: 1, preferredTimescale: 1000)) { [weak recordPlayer] isFinished in
|
|
|
- if isFinished && needPlay{
|
|
|
- recordPlayer?.play()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // 定位到某个时间点,相应进度条的UI更新
|
|
|
- func locationTo(time:CMTime) {
|
|
|
- var toTime = CMTime(seconds: time.seconds, preferredTimescale: 1000)
|
|
|
- if CMTimeCompare(time, recordItem!.materialDuraion) > 0 {
|
|
|
- toTime = recordItem!.materialDuraion
|
|
|
- currentAssetProgress = toTime
|
|
|
- }
|
|
|
- progreddL?.text = CMTimeGetSeconds(currentAssetProgress).formatDurationToHMS()
|
|
|
-
|
|
|
- cameraProgressV?.collectionV.contentOffset = CGPoint(x: currentAssetProgress.seconds * 70.0 / 5.0, y: 0)
|
|
|
-
|
|
|
- }
|
|
|
override func deleteRecord(at: CMTime) {
|
|
|
if let videoS = recordItem?.videoStickers.enumerated().first(where: { mod in
|
|
|
CMTimeCompare(mod.1.timelineCMIn, at) <= 0 && CMTimeCompare(mod.1.timelineCMOut, at) >= 0
|
|
@@ -374,47 +299,68 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- override func changeRecordMaterail(){
|
|
|
- //
|
|
|
-
|
|
|
- if recordItem?.videoStickers.count ?? 0 == 0 {
|
|
|
- currentAssetProgress = .zero
|
|
|
- resetEnv()
|
|
|
- } else {
|
|
|
- cameraProgressV?.collectionV.reloadData()
|
|
|
- cameraProgressV?.collectionV.contentOffset = CGPoint(x: currentAssetProgress.seconds * 70.0 / 5.0, y: 0)
|
|
|
- progreddL?.text = CMTimeGetSeconds(currentAssetProgress).formatDurationToHMS()
|
|
|
-
|
|
|
- cameraProgressV?.isHidden = false
|
|
|
-
|
|
|
- if currentAssetProgress == .zero {
|
|
|
- // 按钮为删除
|
|
|
+
|
|
|
+ // 录制失败 , 不足一秒时恢复上一次状态
|
|
|
+ func revertLast(){
|
|
|
+ if let vmod = recordItem?.videoStickers.last {
|
|
|
+ vmod.timelineCMOut = vmod.timelineCMIn
|
|
|
+ currentAssetProgress = vmod.timelineCMOut
|
|
|
+ recordItem?.thumbImgs.removeAll(where: { img in
|
|
|
+ vmod.thumImgs?.contains(img) ?? false
|
|
|
+ })
|
|
|
+ DispatchQueue.main.async {[weak self] in
|
|
|
+ guard let wself = self else { return }
|
|
|
+
|
|
|
+ wself.cameraProgressV?.collectionV.reloadData()
|
|
|
}
|
|
|
+ vmod.thumImgs?.removeAll()
|
|
|
+ recordItem?.videoStickers.removeLast()
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- override func pause() {
|
|
|
- avplayer.pause()
|
|
|
- recordPlayer?.pause()
|
|
|
- if currentAssetProgress == recordItem?.materialDuraion {
|
|
|
- camera?.resumeCameraCapture()
|
|
|
+ // 使用avplayer进行播放视频和音频
|
|
|
+ override func play() {
|
|
|
+ guard let preView = playView else {
|
|
|
+ return
|
|
|
}
|
|
|
+ if playerLayer.superlayer == nil {
|
|
|
+ preView.layer.addSublayer(playerLayer)
|
|
|
+ }
|
|
|
+
|
|
|
+ camera?.pauseCapture()
|
|
|
+
|
|
|
+ // 100ms以内的重头开始播放
|
|
|
+ if (recordItem?.materialDuraion.seconds)! - currentAssetProgress.seconds < 0.1 {
|
|
|
+ currentAssetProgress = .zero
|
|
|
+ currPlayTime = .zero
|
|
|
+ locationTo(time: currentAssetProgress)
|
|
|
+ avplayer.replaceCurrentItem(with: nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ if avplayer.currentItem != nil {
|
|
|
+ avplayer.play()
|
|
|
+ recordPlayer?.play()
|
|
|
+ }else{
|
|
|
+ prepareToPlayNext()
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- override func dragEnd() {
|
|
|
- // 播放视频
|
|
|
- if let mod = recordItem?.videoStickers.first(where: { m in
|
|
|
- CMTimeCompare(m.timelineCMIn, currentAssetProgress) <= 0 && CMTimeCompare(m.timelineCMOut, currentAssetProgress) > 0
|
|
|
+ func playRecordVoice(_ tt:CMTime, needPlay:Bool = true){
|
|
|
+ // 播放音频
|
|
|
+ if let mod = recordItem?.voiceStickers.first(where: { m in
|
|
|
+ CMTimeCompare(m.startCMTime, currentAssetProgress + CMTime(seconds: 0.033, preferredTimescale: 1000)) <= 0 && CMTimeCompare(m.endCMTime, currentAssetProgress) > 0
|
|
|
}){
|
|
|
- avplayerReplaceItem(newItem: AVPlayerItem(url: URL(fileURLWithPath: mod.locationPath)))
|
|
|
- currPlayTime = mod.timelineCMIn
|
|
|
-
|
|
|
- let tt = currentAssetProgress - currPlayTime
|
|
|
- BFLog(1, message: "asset - tt: \(tt.seconds), curr:\(currentAssetProgress.seconds)")
|
|
|
- avplayer.seek(to: tt, toleranceBefore: CMTime(seconds: 1, preferredTimescale: 1000), toleranceAfter: CMTime(seconds: 1, preferredTimescale: 1000))
|
|
|
-
|
|
|
- playRecordVoice(tt, needPlay: false)
|
|
|
+ recordPlayer?.replaceCurrentItem(with: AVPlayerItem(url: URL(fileURLWithPath: mod.wavFilePath)))
|
|
|
+
|
|
|
+ BFLog(1, message: "record - tt: \(tt.seconds), curr:\(currentAssetProgress.seconds)")
|
|
|
+ recordPlayer?.currentItem?.seek(to: tt, toleranceBefore: CMTime(seconds: 1, preferredTimescale: 1000), toleranceAfter: CMTime(seconds: 1, preferredTimescale: 1000)) { [weak recordPlayer] isFinished in
|
|
|
+ if needPlay{
|
|
|
+ recordPlayer?.play()
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -456,6 +402,48 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ override func pause() {
|
|
|
+ avplayer.pause()
|
|
|
+ recordPlayer?.pause()
|
|
|
+ if currentAssetProgress == recordItem?.materialDuraion {
|
|
|
+ camera?.resumeCameraCapture()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override func dragEnd() {
|
|
|
+ // 播放视频
|
|
|
+ if let mod = recordItem?.videoStickers.first(where: { m in
|
|
|
+ CMTimeCompare(m.timelineCMIn, currentAssetProgress) <= 0 && CMTimeCompare(m.timelineCMOut, currentAssetProgress) > 0
|
|
|
+ }){
|
|
|
+ avplayerReplaceItem(newItem: AVPlayerItem(url: URL(fileURLWithPath: mod.locationPath)))
|
|
|
+ currPlayTime = mod.timelineCMIn
|
|
|
+
|
|
|
+ let tt = currentAssetProgress - currPlayTime
|
|
|
+ BFLog(1, message: "asset - tt: \(tt.seconds), curr:\(currentAssetProgress.seconds)")
|
|
|
+ avplayer.seek(to: tt, toleranceBefore: CMTime(seconds: 1, preferredTimescale: 1000), toleranceAfter: CMTime(seconds: 1, preferredTimescale: 1000))
|
|
|
+
|
|
|
+ playRecordVoice(tt, needPlay: false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override func changeRecordMaterail(){
|
|
|
+ //
|
|
|
+ if recordItem?.videoStickers.count ?? 0 == 0 {
|
|
|
+ currentAssetProgress = .zero
|
|
|
+ resetEnv()
|
|
|
+ } else {
|
|
|
+ cameraProgressV?.collectionV.reloadData()
|
|
|
+ cameraProgressV?.collectionV.contentOffset = CGPoint(x: currentAssetProgress.seconds * 70.0 / 5.0, y: 0)
|
|
|
+ progreddL?.text = CMTimeGetSeconds(currentAssetProgress).formatDurationToHMS()
|
|
|
+
|
|
|
+ cameraProgressV?.isHidden = false
|
|
|
+
|
|
|
+ if currentAssetProgress == .zero {
|
|
|
+ // 按钮为删除
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
override func clean() {
|
|
|
filter.removeTarget(movieWrite)
|
|
|
filter.removeTarget(rendView)
|
|
@@ -464,6 +452,20 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
|
|
|
}
|
|
|
|
|
|
// MARK: - 私有方法
|
|
|
+
|
|
|
+ // 定位到某个时间点,相应进度条的UI更新
|
|
|
+ func locationTo(time:CMTime) {
|
|
|
+ var toTime = CMTime(seconds: time.seconds, preferredTimescale: 1000)
|
|
|
+ if CMTimeCompare(time, recordItem!.materialDuraion) > 0 {
|
|
|
+ toTime = recordItem!.materialDuraion
|
|
|
+ currentAssetProgress = toTime
|
|
|
+ }
|
|
|
+ progreddL?.text = CMTimeGetSeconds(currentAssetProgress).formatDurationToHMS()
|
|
|
+
|
|
|
+ cameraProgressV?.collectionV.contentOffset = CGPoint(x: currentAssetProgress.seconds * 70.0 / 5.0, y: 0)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
func updateUI(progress:CMTime){
|
|
|
DispatchQueue.main.async {[weak self] in
|
|
|
guard let wself = self else { return }
|