|
@@ -914,6 +914,10 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
jumpTime = model.startTime
|
|
jumpTime = model.startTime
|
|
|
|
+
|
|
|
|
+ if itemModels[currItemModelIndex].mediaType == .IMAGE {
|
|
|
|
+ itemModels[currItemModelIndex].materialDuraion = jumpTime
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} else if action.type == 3 {
|
|
} else if action.type == 3 {
|
|
// 删除录音
|
|
// 删除录音
|
|
@@ -934,8 +938,12 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
itemModels[currItemModelIndex].titleStickers.insert(titleTuple.0, at: titleTuple.1)
|
|
itemModels[currItemModelIndex].titleStickers.insert(titleTuple.0, at: titleTuple.1)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ if itemModels[currItemModelIndex].mediaType == .IMAGE {
|
|
|
|
+ itemModels[currItemModelIndex].materialDuraion = itemModels[currItemModelIndex].voiceStickers.last?.endTime ?? 0
|
|
|
|
+ }
|
|
} else {}
|
|
} else {}
|
|
events.removeLast()
|
|
events.removeLast()
|
|
|
|
+
|
|
let dur = itemModels[currItemModelIndex].materialDuraion
|
|
let dur = itemModels[currItemModelIndex].materialDuraion
|
|
if dur > 0 {
|
|
if dur > 0 {
|
|
changeProgress(progress: Float(jumpTime / dur))
|
|
changeProgress(progress: Float(jumpTime / dur))
|
|
@@ -1132,7 +1140,9 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
self?.assetPlayer?.volume = self?.noSpeakVolume ?? 0
|
|
self?.assetPlayer?.volume = self?.noSpeakVolume ?? 0
|
|
didPlayToEndTime(recordedAudio, newItem)
|
|
didPlayToEndTime(recordedAudio, newItem)
|
|
}
|
|
}
|
|
- _ = recordPlayer?.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 1000), queue: DispatchQueue.global()) { time in
|
|
|
|
|
|
+ avplayerTimeObserver?.invalidate()
|
|
|
|
+ avplayerTimeObserver = recordPlayer?.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 1000), queue: DispatchQueue.global()) { time in
|
|
|
|
+ BFLog(1, message: "")
|
|
periodicTimeObserver(time, newItem)
|
|
periodicTimeObserver(time, newItem)
|
|
} as? NSKeyValueObservation
|
|
} as? NSKeyValueObservation
|
|
}
|
|
}
|
|
@@ -1178,14 +1188,16 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
func play() {
|
|
func play() {
|
|
BFLog(1, message: "开始播放 \(currentAssetProgress.seconds)")
|
|
BFLog(1, message: "开始播放 \(currentAssetProgress.seconds)")
|
|
// add by ak 播放前设置 AVAudioSession 为播放状态
|
|
// add by ak 播放前设置 AVAudioSession 为播放状态
|
|
- let a = Date()
|
|
|
|
- do {
|
|
|
|
- try AVAudioSession.sharedInstance().setCategory(.playback)
|
|
|
|
- try AVAudioSession.sharedInstance().setActive(true)
|
|
|
|
- } catch {
|
|
|
|
-
|
|
|
|
|
|
+ if AVAudioSession.sharedInstance().category != .playback {
|
|
|
|
+ let a = Date()
|
|
|
|
+ do {
|
|
|
|
+ try AVAudioSession.sharedInstance().setCategory(.playback)
|
|
|
|
+ try AVAudioSession.sharedInstance().setActive(true)
|
|
|
|
+ } catch {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ BFLog(1, message: "开启session \(Date().timeIntervalSince(a))")
|
|
}
|
|
}
|
|
- BFLog(1, message: "开启session \(Date().timeIntervalSince(a))")
|
|
|
|
|
|
|
|
isNormalPlaying = true
|
|
isNormalPlaying = true
|
|
if isEndPlay {
|
|
if isEndPlay {
|
|
@@ -1290,7 +1302,9 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
assetPlayer?.replaceCurrentItem(with: item)
|
|
assetPlayer?.replaceCurrentItem(with: item)
|
|
} else {
|
|
} else {
|
|
assetPlayer = AVPlayer(playerItem: item)
|
|
assetPlayer = AVPlayer(playerItem: item)
|
|
- assetPlayer?.volume = 0
|
|
|
|
|
|
+ assetPlayer?.volume = self.noSpeakVolume
|
|
|
|
+
|
|
|
|
+ avplayerTimeObserver?.invalidate()
|
|
avplayerTimeObserver = assetPlayer?.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 1000), queue: DispatchQueue.global()) { [weak self] time in
|
|
avplayerTimeObserver = assetPlayer?.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 1000), queue: DispatchQueue.global()) { [weak self] time in
|
|
// 进度监控
|
|
// 进度监控
|
|
self?.periodicTimeObserver(item: item, time: time)
|
|
self?.periodicTimeObserver(item: item, time: time)
|
|
@@ -1529,12 +1543,12 @@ extension BFRecordScreenController: UICollectionViewDelegate, UICollectionViewDa
|
|
// 更新缩略图
|
|
// 更新缩略图
|
|
progressThumV.recordItem = recordItem
|
|
progressThumV.recordItem = recordItem
|
|
progressThumV.isHidden = false
|
|
progressThumV.isHidden = false
|
|
|
|
+ progreddL.text = "00:00"
|
|
// 重置指针
|
|
// 重置指针
|
|
currentAssetProgress = CMTime(seconds: 0, preferredTimescale: 1000)
|
|
currentAssetProgress = CMTime(seconds: 0, preferredTimescale: 1000)
|
|
// 重置播放器
|
|
// 重置播放器
|
|
assetPlayer?.seek(to: CMTime.zero)
|
|
assetPlayer?.seek(to: CMTime.zero)
|
|
recordPlayer?.seek(to: CMTime.zero)
|
|
recordPlayer?.seek(to: CMTime.zero)
|
|
-
|
|
|
|
// 重设撤销栈
|
|
// 重设撤销栈
|
|
events.append(WithDrawModel(type: 0, timestamp: 0))
|
|
events.append(WithDrawModel(type: 0, timestamp: 0))
|
|
itemModels[currItemModelIndex].events = events
|
|
itemModels[currItemModelIndex].events = events
|
|
@@ -1577,7 +1591,7 @@ public extension BFRecordScreenController {
|
|
}
|
|
}
|
|
isNormalPlaying = true
|
|
isNormalPlaying = true
|
|
playRecord(at: currentAssetProgress, periodicTimeObserver: { [weak self] currentT, currentItem in
|
|
playRecord(at: currentAssetProgress, periodicTimeObserver: { [weak self] currentT, currentItem in
|
|
- BFLog(message: "播放第段进度:\(currentT),\(currentItem)")
|
|
|
|
|
|
+ BFLog(1, message: "播放第段进度:\(currentT),\(currentItem)")
|
|
self?.imageRecordProgress(progress: CMTimeGetSeconds(currentT))
|
|
self?.imageRecordProgress(progress: CMTimeGetSeconds(currentT))
|
|
}, didPlayToEndTime: { [weak self] recordItem, currentItem in
|
|
}, didPlayToEndTime: { [weak self] recordItem, currentItem in
|
|
BFLog(message: "播放第段结束:\(String(describing: recordItem)),\(String(describing: currentItem))")
|
|
BFLog(message: "播放第段结束:\(String(describing: recordItem)),\(String(describing: currentItem))")
|
|
@@ -1605,7 +1619,7 @@ public extension BFRecordScreenController {
|
|
} else {
|
|
} else {
|
|
currentAssetProgress = CMTime(seconds: recordStartPlayTime.seconds + progress, preferredTimescale: 1000)
|
|
currentAssetProgress = CMTime(seconds: recordStartPlayTime.seconds + progress, preferredTimescale: 1000)
|
|
}
|
|
}
|
|
- BFLog(message: "图片录音进度:\(progress),currentAssetProgress=\(currentAssetProgress),\(itemModels[currItemModelIndex].materialDuraion)")
|
|
|
|
|
|
+ BFLog(1, message: "图片录音进度:\(progress),currentAssetProgress=\(currentAssetProgress),\(itemModels[currItemModelIndex].materialDuraion)")
|
|
if itemModels[currItemModelIndex].mediaType == .IMAGE {
|
|
if itemModels[currItemModelIndex].mediaType == .IMAGE {
|
|
DispatchQueue.main.async { [weak self] in
|
|
DispatchQueue.main.async { [weak self] in
|
|
self?.progreddL.text = String(format: "%@", (self?.currentAssetProgress.seconds ?? 0).formatDurationToHMS())
|
|
self?.progreddL.text = String(format: "%@", (self?.currentAssetProgress.seconds ?? 0).formatDurationToHMS())
|