|
@@ -449,19 +449,26 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
let header = dicResult?["header"] as? [String: Any]
|
|
|
let payload = dicResult?["payload"] as? [String: Any]
|
|
|
|
|
|
- BFLog(message: "识别结果:) \((payload?["result"])!) startTime:\(self?.recorderManager?.voiceModel?.startTime ?? 0.0)")
|
|
|
+ BFLog(message: "识别结果:) \((payload?["result"])!) startTime:\(self?.recorderManager?.voiceModel?.startCMTime.seconds ?? 0.0)")
|
|
|
DispatchQueue.main.async {
|
|
|
- // 1,保存字幕数据 begin_time是开始出现文字的时间,time 是结束文字出现的时间 单位都为毫秒,都是相对于录制音频数据整段时间。self.recorderManager.voiceModel?.startTime 为开始的录制的时间,开始和结束都要加上这个时差
|
|
|
+ // 1,保存字幕数据 begin_time是开始出现文字的时间,time 是结束文字出现的时间 单位都为毫秒,都是相对于录制音频数据整段时间。self.recorderManager.voiceModel?.startCMTime.seconds 为开始的录制的时间,开始和结束都要加上这个时差
|
|
|
|
|
|
let newSubtitle = PQEditSubTitleModel()
|
|
|
// 任务全局唯一ID,请记录该值,便于排查问题。 每次 startRecorder 和 stopRecoder 之间 task_Id都不会变化
|
|
|
newSubtitle.taskID = (header?["task_id"] as? String) ?? ""
|
|
|
|
|
|
// 这里加300ms 是因为返回结果为了切到字,时长提前一些时间,具体时间官方没说和原音频有关系。这里我们先延后300ms 单位:毫秒。
|
|
|
-
|
|
|
- newSubtitle.timelineIn = (self?.recorderManager?.voiceModel?.startTime ?? 0.0) + Float64((((payload?["begin_time"]) as? Int) ?? 0) + 300) / 1000.0
|
|
|
-
|
|
|
- newSubtitle.timelineOut = (self?.recorderManager?.voiceModel?.startTime ?? 0.0) + Float64(((payload?["time"]) as? Int) ?? 0) / 1000.0
|
|
|
+ if audioFilePath == self?.recorderManager?.voiceModel?.wavFilePath ?? "aa" {
|
|
|
+ newSubtitle.timelineIn = (self?.recorderManager?.voiceModel?.startCMTime.seconds ?? 0.0) + Float64((((payload?["begin_time"]) as? Int) ?? 0) + 300) / 1000.0
|
|
|
+ newSubtitle.timelineOut = (self?.recorderManager?.voiceModel?.startCMTime.seconds ?? 0.0) + Float64(((payload?["time"]) as? Int) ?? 0) / 1000.0
|
|
|
+ } else {
|
|
|
+ if let voice = self?.itemModels[self?.currItemModelIndex ?? 0].voiceStickers.first(where: { m in
|
|
|
+ m.wavFilePath == audioFilePath
|
|
|
+ }) {
|
|
|
+ newSubtitle.timelineIn = voice.startCMTime.seconds + Float64((((payload?["begin_time"]) as? Int) ?? 0) + 300) / 1000.0
|
|
|
+ newSubtitle.timelineOut = voice.startCMTime.seconds + Float64(((payload?["time"]) as? Int) ?? 0) / 1000.0
|
|
|
+ }
|
|
|
+ }
|
|
|
var showText = ((payload?["result"]) as? String) ?? ""
|
|
|
if showText.count > subtitleMaxlength {
|
|
|
showText = showText.substring(to: subtitleMaxlength)
|
|
@@ -480,16 +487,16 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
recorderManager?.endRecordHandle = { [weak self] voideModel, _ in
|
|
|
if let sself = self, let model = voideModel, FileManager.default.fileExists(atPath: model.wavFilePath ?? "") {
|
|
|
// 加入到语音数组里
|
|
|
- model.endTime = sself.currentAssetProgress.seconds
|
|
|
- BFLog(message: "录制结束当前录音文件:\(model.wavFilePath ?? "")-\(model.startTime)-\(model.endTime)-\(model.endTime - model.startTime)")
|
|
|
+ model.endCMTime = sself.currentAssetProgress
|
|
|
+ BFLog(1, message: "录制结束当前录音文件:\(model.wavFilePath ?? "")-\(model.startCMTime.seconds)-\(model.endCMTime.seconds)-\(model.endCMTime.seconds - model.startCMTime.seconds)")
|
|
|
// ********** 开始处理冲突的录制部分
|
|
|
- let newRange = CMTimeRange(start: CMTime(seconds: model.startTime, preferredTimescale: 1000), end: CMTime(seconds: model.endTime, preferredTimescale: 1000))
|
|
|
+ let newRange = CMTimeRange(start: model.startCMTime, end: model.endCMTime)
|
|
|
|
|
|
var deletedVoices = [(PQVoiceModel, Int)]()
|
|
|
// 要删除的字幕
|
|
|
var deletedTitlesTemp = [(PQEditSubTitleModel, Int)]()
|
|
|
for (i, m) in sself.itemModels[sself.currItemModelIndex].voiceStickers.enumerated() {
|
|
|
- let originRange = CMTimeRange(start: CMTime(seconds: m.startTime, preferredTimescale: 1000), end: CMTime(seconds: m.endTime - 0.001, preferredTimescale: 1000))
|
|
|
+ let originRange = CMTimeRange(start: m.startCMTime, end: CMTime(seconds: m.endCMTime.seconds - 0.001, preferredTimescale: 1000))
|
|
|
if CMTimeRangeGetIntersection(originRange, otherRange: newRange).duration.seconds > 0 {
|
|
|
deletedVoices.append((m, i))
|
|
|
deletedTitlesTemp += sself.deleteTitles(voiceModel: m)
|
|
@@ -502,30 +509,31 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
m.wavFilePath == tempM.wavFilePath
|
|
|
}
|
|
|
}
|
|
|
- BFLog(1, message: "添加录音文件:\(model.startTime) -- \(model.endTime)")
|
|
|
+ BFLog(1, message: "添加录音文件:\(model.startCMTime.seconds) -- \(model.endCMTime.seconds)")
|
|
|
sself.itemModels[sself.currItemModelIndex].voiceStickers.append(model)
|
|
|
// 如果是图片素材同时有需要删除的录音时需要调整录音文件开始结束时间
|
|
|
+ // warning: 图片录制的时候应该只能在结尾处录制
|
|
|
if sself.itemModels[sself.currItemModelIndex].mediaType == .IMAGE {
|
|
|
if deletedVoices.count > 0 {
|
|
|
// 如果是图片先排序在计算区间
|
|
|
sself.itemModels[sself.currItemModelIndex].voiceStickers = sself.itemModels[sself.currItemModelIndex].voiceStickers.sorted { voice1, voice2 in
|
|
|
- voice1.startTime < voice2.startTime
|
|
|
+ voice1.startCMTime.seconds < voice2.startCMTime.seconds
|
|
|
}
|
|
|
for (index, item) in sself.itemModels[sself.currItemModelIndex].voiceStickers.enumerated() {
|
|
|
if index > 0 {
|
|
|
// 注:开始时间减去duration or 等一前一段录音的结束时间
|
|
|
- let tempDuration = item.endTime - item.startTime
|
|
|
- item.startTime = sself.itemModels[sself.currItemModelIndex].voiceStickers[index - 1].endTime
|
|
|
- item.endTime = item.startTime + tempDuration
|
|
|
+ let tempDuration = item.endCMTime.seconds - item.startCMTime.seconds
|
|
|
+ item.startCMTime = CMTime(seconds: sself.itemModels[sself.currItemModelIndex].voiceStickers[index - 1].endCMTime.seconds, preferredTimescale: 1000)
|
|
|
+ item.endCMTime = CMTime(seconds: item.startCMTime.seconds + tempDuration, preferredTimescale: 1000)
|
|
|
}
|
|
|
- BFLog(message: "录制结束重新排序录音文件:\(index)-\(item.wavFilePath ?? "")-\(item.startTime)-\(item.endTime)-\(item.endTime - item.startTime)")
|
|
|
+ BFLog(message: "录制结束重新排序录音文件:\(index)-\(item.wavFilePath ?? "")-\(item.startCMTime.seconds)-\(item.endCMTime.seconds)-\(item.endCMTime.seconds - item.startCMTime.seconds)")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// ***********处理冲突的录音部分资源 end
|
|
|
|
|
|
// 添加撤销记录点
|
|
|
- var event = WithDrawModel(type: 2, timestamp: model.startTime)
|
|
|
+ var event = WithDrawModel(type: 2, timestamp: model.startCMTime.seconds)
|
|
|
event.deletedVoices = deletedVoices
|
|
|
event.deletedTittles = deletedTitlesTemp
|
|
|
sself.events.append(event)
|
|
@@ -533,9 +541,9 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
if sself.itemModels[sself.currItemModelIndex].mediaType == .IMAGE {
|
|
|
var duration: Double = 0
|
|
|
sself.itemModels[sself.currItemModelIndex].voiceStickers.forEach { temp in
|
|
|
- BFLog(message: "录制结束-最终:\(temp.wavFilePath ?? "")-\(temp.startTime)-\(temp.endTime)-\(temp.endTime - temp.startTime)")
|
|
|
- temp.duration = "\(temp.endTime - temp.startTime)"
|
|
|
- duration = duration + (temp.endTime - temp.startTime)
|
|
|
+ BFLog(message: "录制结束-最终:\(temp.wavFilePath ?? "")-\(temp.startCMTime.seconds)-\(temp.endCMTime.seconds)-\(temp.endCMTime.seconds - temp.startCMTime.seconds)")
|
|
|
+ temp.duration = "\(temp.endCMTime.seconds - temp.startCMTime.seconds)"
|
|
|
+ duration = duration + (temp.endCMTime.seconds - temp.startCMTime.seconds)
|
|
|
}
|
|
|
sself.itemModels[sself.currItemModelIndex].materialDuraion = Double(String(format: "%.3f", duration)) ?? 0
|
|
|
self?.isEndPlay = true
|
|
@@ -546,7 +554,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
// 录音完,重绘撤销按钮,更新录音按钮,
|
|
|
self?.changeWithDrawBtnLayout(2)
|
|
|
// 注:在录制结束时矫正当前位置,避免跟指针无法对其
|
|
|
- self?.indirectionView?.resetCurrentItem(start: model.startTime, end: model.endTime)
|
|
|
+ self?.indirectionView?.resetCurrentItem(start: model.startCMTime.seconds, end: model.endCMTime.seconds)
|
|
|
if deletedVoices.count > 0 {
|
|
|
/// 重绘录音进度视图
|
|
|
self?.resetAllIndirectionView()
|
|
@@ -576,7 +584,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
subtitleCount = self?.itemModels[self?.currItemModelIndex ?? 0].titleStickers.count ?? 0
|
|
|
BFLog(2, message: "删除\(voiceModel?.wavFilePath ?? "")对应的字幕 后 count\(subtitleCount)")
|
|
|
/// 重置进度
|
|
|
- self?.currentAssetProgress = CMTime(seconds: voiceModel?.startTime ?? 0, preferredTimescale: 1000)
|
|
|
+ self?.currentAssetProgress = CMTime(seconds: voiceModel?.startCMTime.seconds ?? 0, preferredTimescale: 1000)
|
|
|
self?.resetCurrentProgress()
|
|
|
// 移除
|
|
|
self?.indirectionView?.deleteItem(isCurrent: true)
|
|
@@ -661,7 +669,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
@objc func editSubtitle() {
|
|
|
BFLog(message: "编辑字幕 index:\(showSubtitleIndex)")
|
|
|
- if !isNormalPlaying && subtitleLabel.text?.count != 0{
|
|
|
+ if !isNormalPlaying, subtitleLabel.text?.count != 0 {
|
|
|
subtitleEditView.isHidden = false
|
|
|
subtitleEditView.textView.becomeFirstResponder()
|
|
|
subtitleEditView.setNewText(text: subtitleLabel.text ?? "", index: showSubtitleIndex)
|
|
@@ -678,7 +686,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
for (index, subtitle) in itemModels[currItemModelIndex].titleStickers.enumerated() {
|
|
|
if subtitle.timelineIn <= CMTimeGetSeconds(time), subtitle.timelineOut >= CMTimeGetSeconds(time) {
|
|
|
findShowSubtitle = subtitle
|
|
|
- BFLog(message: "找到要显示的字幕 in \(findShowSubtitle?.timelineIn ?? 0.0) out \(findShowSubtitle?.timelineOut ?? 0.0) text:\(findShowSubtitle?.text ?? "") currTime is \(CMTimeGetSeconds(time))")
|
|
|
+ BFLog(1, message: "找到要显示的字幕 in \(findShowSubtitle?.timelineIn ?? 0.0) out \(findShowSubtitle?.timelineOut ?? 0.0) text:\(findShowSubtitle?.text ?? "") currTime is \(CMTimeGetSeconds(time))")
|
|
|
showSubtitleIndex = index
|
|
|
break
|
|
|
}
|
|
@@ -867,7 +875,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
/// 删除指定段落的所有字幕 数据
|
|
|
/// - Parameter voiceModel: 删除的音频数据
|
|
|
func deleteTitles(voiceModel: PQVoiceModel) -> [(PQEditSubTitleModel, Int)] {
|
|
|
- BFLog(message: "itemModels[currItemModelIndex].titleStickers 删除前:\(itemModels[currItemModelIndex].titleStickers.count) model.startTime: \(voiceModel.startTime) model.end: \(voiceModel.endTime)")
|
|
|
+ BFLog(message: "itemModels[currItemModelIndex].titleStickers 删除前:\(itemModels[currItemModelIndex].titleStickers.count) model.startCMTime.seconds: \(voiceModel.startCMTime.seconds) model.end: \(voiceModel.endCMTime.seconds)")
|
|
|
var deleteTemp = [(PQEditSubTitleModel, Int)]()
|
|
|
|
|
|
for (index, title) in itemModels[currItemModelIndex].titleStickers.enumerated() {
|
|
@@ -901,16 +909,20 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
events.append(event)
|
|
|
// 注:删除录音后图片素材需要回撤指针进度,同时后面录音往前挪
|
|
|
if itemModels[currItemModelIndex].mediaType == .IMAGE {
|
|
|
- let currDuration = model.endTime - model.startTime
|
|
|
+ let currDuration = model.endCMTime.seconds - model.startCMTime.seconds
|
|
|
itemModels[currItemModelIndex].materialDuraion = itemModels[currItemModelIndex].materialDuraion - currDuration
|
|
|
- currentAssetProgress = CMTime(seconds: model.startTime, preferredTimescale: 1000)
|
|
|
+ currentAssetProgress = CMTime(seconds: model.startCMTime.seconds, preferredTimescale: 1000)
|
|
|
// 更新进度
|
|
|
resetCurrentProgress()
|
|
|
for (index, item) in itemModels[currItemModelIndex].voiceStickers.enumerated() {
|
|
|
if index >= isStopAtRecordRange {
|
|
|
// 注:开始时间减去duration or 等一前一段录音的结束时间
|
|
|
- item.startTime -= currDuration
|
|
|
- item.endTime -= currDuration
|
|
|
+// item.startCMTime.seconds -= currDuration
|
|
|
+// item.endCMTime.seconds -= currDuration
|
|
|
+ let startTime = item.startCMTime.seconds
|
|
|
+ let endTime = item.endCMTime.seconds
|
|
|
+ item.startCMTime = CMTime(seconds: startTime - currDuration, preferredTimescale: 1000)
|
|
|
+ item.endCMTime = CMTime(seconds: endTime - currDuration, preferredTimescale: 1000)
|
|
|
}
|
|
|
}
|
|
|
/// 重绘录音进度视图
|
|
@@ -935,6 +947,9 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
isRecording = true
|
|
|
progressThumV.progressView.isUserInteractionEnabled = false
|
|
|
collectionView.isScrollEnabled = false
|
|
|
+ // 开始录制时清除屏幕上的字幕
|
|
|
+ subtitleLabel.text = ""
|
|
|
+
|
|
|
pause()
|
|
|
if recorderManager == nil {
|
|
|
BFLog(message: "录音机初始化错误!!!")
|
|
@@ -945,7 +960,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
let model = PQVoiceModel()
|
|
|
// 开始时间
|
|
|
- model.startTime = currentAssetProgress.seconds
|
|
|
+ model.startCMTime = currentAssetProgress
|
|
|
model.volume = 100
|
|
|
recorderManager?.voiceModel = model
|
|
|
recorderManager?.startRecord()
|
|
@@ -980,19 +995,19 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
view.isUserInteractionEnabled = true
|
|
|
recorderManager?.stopRecord(isCancel: false)
|
|
|
|
|
|
- if currentAssetProgress.seconds - (recorderManager?.voiceModel?.startTime ?? 0) >= 1.0 {
|
|
|
+ if currentAssetProgress.seconds - (recorderManager?.voiceModel?.startCMTime.seconds ?? 0) >= 1.0 {
|
|
|
} else {
|
|
|
- let startTime = recorderManager?.voiceModel?.startTime ?? 0
|
|
|
+ let startTime = recorderManager?.voiceModel?.startCMTime.seconds ?? 0
|
|
|
changeProgress(progress: Float(startTime / itemModels[currItemModelIndex].materialDuraion))
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- if currentAssetProgress.seconds - (recorderManager?.voiceModel?.startTime ?? 0 ) >= 1.0 {
|
|
|
+ if currentAssetProgress.seconds - (recorderManager?.voiceModel?.startCMTime.seconds ?? 0 ) >= 1.0 {
|
|
|
recorderManager?.stopRecord(isCancel: false)
|
|
|
changeWithDrawBtnLayout(2)
|
|
|
}else{
|
|
|
recorderManager?.stopRecord(isCancel: true)
|
|
|
- changeProgress(progress: Float(recorderManager?.voiceModel?.startTime ?? 0))
|
|
|
+ changeProgress(progress: Float(recorderManager?.voiceModel?.startCMTime.seconds ?? 0))
|
|
|
}
|
|
|
*/
|
|
|
if !avatarView.isHidden {
|
|
@@ -1017,7 +1032,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
if action.type == 2 {
|
|
|
// 撤销录制
|
|
|
if let modelIndex = itemModels[currItemModelIndex].voiceStickers.firstIndex(where: { mod in
|
|
|
- mod.startTime == action.timestamp
|
|
|
+ mod.startCMTime.seconds == action.timestamp
|
|
|
}) {
|
|
|
// 移除音频
|
|
|
let model = itemModels[currItemModelIndex].voiceStickers[modelIndex]
|
|
@@ -1047,7 +1062,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
itemModels[currItemModelIndex].titleStickers.insert(titleTuple.0, at: titleTuple.1)
|
|
|
}
|
|
|
}
|
|
|
- jumpTime = model.startTime
|
|
|
+ jumpTime = model.startCMTime.seconds
|
|
|
|
|
|
if itemModels[currItemModelIndex].mediaType == .IMAGE {
|
|
|
itemModels[currItemModelIndex].materialDuraion = jumpTime
|
|
@@ -1066,13 +1081,17 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
} else {
|
|
|
tuples?.forEach { tuple in
|
|
|
itemModels[currItemModelIndex].voiceStickers.insert(tuple.0, at: tuple.1)
|
|
|
- let currDuration = tuple.0.endTime - tuple.0.startTime
|
|
|
+ let currDuration = tuple.0.endCMTime.seconds - tuple.0.startCMTime.seconds
|
|
|
itemModels[currItemModelIndex].materialDuraion = itemModels[currItemModelIndex].materialDuraion + currDuration
|
|
|
for (index, item) in itemModels[currItemModelIndex].voiceStickers.enumerated() {
|
|
|
if index > tuple.1 {
|
|
|
// 注:开始时间减去duration or 等一前一段录音的结束时间
|
|
|
- item.startTime += currDuration
|
|
|
- item.endTime += currDuration
|
|
|
+// item.startCMTime.seconds -= currDuration
|
|
|
+// item.endCMTime.seconds -= currDuration
|
|
|
+ let startTime = item.startCMTime.seconds
|
|
|
+ let endTime = item.endCMTime.seconds
|
|
|
+ item.startCMTime = CMTime(seconds: startTime + currDuration, preferredTimescale: 1000)
|
|
|
+ item.endCMTime = CMTime(seconds: endTime + currDuration, preferredTimescale: 1000)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1085,7 +1104,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
}
|
|
|
if itemModels[currItemModelIndex].mediaType == .IMAGE {
|
|
|
- itemModels[currItemModelIndex].materialDuraion = itemModels[currItemModelIndex].voiceStickers.last?.endTime ?? 0
|
|
|
+ itemModels[currItemModelIndex].materialDuraion = itemModels[currItemModelIndex].voiceStickers.last?.endCMTime.seconds ?? 0
|
|
|
}
|
|
|
|
|
|
} else {}
|
|
@@ -1175,7 +1194,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
func searchStopAtRecordRange(needAdsorb: Bool = false) {
|
|
|
// TODO: 滑动,播放暂停,撤销时,判断是否停止录音区间,是则删除相关录音,画笔,头像,字幕
|
|
|
let elems = itemModels[currItemModelIndex].voiceStickers.enumerated().filter { elem in
|
|
|
- elem.1.startTime <= self.currentAssetProgress.seconds && (elem.1.endTime - 0.001) > self.currentAssetProgress.seconds
|
|
|
+ elem.1.startCMTime.seconds <= self.currentAssetProgress.seconds && (elem.1.endCMTime.seconds - 0.001) > self.currentAssetProgress.seconds
|
|
|
}
|
|
|
|
|
|
isEndPlay = false
|
|
@@ -1183,11 +1202,11 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
if elems.count > 0 {
|
|
|
// TODO: 停在了录音区间,显示删除按钮
|
|
|
if needAdsorb {
|
|
|
- if fabs(elems[0].1.endTime - currentAssetProgress.seconds) < 0.5 {
|
|
|
+ if fabs(elems[0].1.endCMTime.seconds - currentAssetProgress.seconds) < 0.5 {
|
|
|
BFLog(1, message: "吸附在录音结尾")
|
|
|
// changeWithDrawBtnLayout(false)
|
|
|
- changeProgress(progress: Float(elems[0].1.endTime / itemModels[currItemModelIndex].materialDuraion))
|
|
|
- progressThumV.progress = elems[0].1.endTime
|
|
|
+ changeProgress(progress: Float(elems[0].1.endCMTime.seconds / itemModels[currItemModelIndex].materialDuraion))
|
|
|
+ progressThumV.progress = elems[0].1.endCMTime.seconds
|
|
|
|
|
|
// deleteRecordBtn.isHidden = true
|
|
|
// recordBtn.isHidden = false
|
|
@@ -1195,24 +1214,24 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
// BFLog(1, message: "停在了录音区间外 \(isStopAtRecordRange)")
|
|
|
searchStopAtRecordRange(needAdsorb: false)
|
|
|
} else {
|
|
|
- if fabs(elems[0].1.startTime - currentAssetProgress.seconds) < 0.5 {
|
|
|
+ if fabs(elems[0].1.startCMTime.seconds - currentAssetProgress.seconds) < 0.5 {
|
|
|
BFLog(1, message: "吸附在录音开始")
|
|
|
// changeWithDrawBtnLayout(true)
|
|
|
- changeProgress(progress: Float(elems[0].1.startTime / itemModels[currItemModelIndex].materialDuraion))
|
|
|
- progressThumV.progress = elems[0].1.startTime
|
|
|
+ changeProgress(progress: Float(elems[0].1.startCMTime.seconds / itemModels[currItemModelIndex].materialDuraion))
|
|
|
+ progressThumV.progress = elems[0].1.startCMTime.seconds
|
|
|
}
|
|
|
deleteRecordBtn.isHidden = false
|
|
|
recordBtn.isHidden = true
|
|
|
isStopAtRecordRange = elems.first!.0
|
|
|
|
|
|
- BFLog(1, message: "停在了录音区间里 \(isStopAtRecordRange), currTime:\(currentAssetProgress.seconds), 录音范围:\(elems[0].1.startTime) - \(elems[0].1.endTime)")
|
|
|
+ BFLog(1, message: "停在了录音区间里 \(isStopAtRecordRange), currTime:\(currentAssetProgress.seconds), 录音范围:\(elems[0].1.startCMTime.seconds) - \(elems[0].1.endCMTime.seconds)")
|
|
|
}
|
|
|
} else {
|
|
|
deleteRecordBtn.isHidden = false
|
|
|
recordBtn.isHidden = true
|
|
|
|
|
|
isStopAtRecordRange = elems.first!.0
|
|
|
- BFLog(1, message: "停在了录音区间里 \(isStopAtRecordRange), currTime:\(currentAssetProgress.seconds), 录音范围:\(elems[0].1.startTime) - \(elems[0].1.endTime)")
|
|
|
+ BFLog(1, message: "停在了录音区间里 \(isStopAtRecordRange), currTime:\(currentAssetProgress.seconds), 录音范围:\(elems[0].1.startCMTime.seconds) - \(elems[0].1.endCMTime.seconds)")
|
|
|
}
|
|
|
|
|
|
} else {
|
|
@@ -1280,16 +1299,16 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
return
|
|
|
}
|
|
|
let list = itemModels[currItemModelIndex].voiceStickers.sorted { m1, m2 in
|
|
|
- m1.startTime < m2.startTime
|
|
|
+ m1.startCMTime.seconds < m2.startCMTime.seconds
|
|
|
}
|
|
|
let (shouldPlayRecordIndex, recordedAudio) = list.enumerated().first { model in
|
|
|
- model.1.endTime > CMTimeGetSeconds(currentT)
|
|
|
+ model.1.endCMTime.seconds > CMTimeGetSeconds(currentT)
|
|
|
} ?? (-1, nil)
|
|
|
|
|
|
guard let recordedAudio = recordedAudio, recordedAudio.wavFilePath.count > 0 else {
|
|
|
return
|
|
|
}
|
|
|
- BFLog(1, message: "当前时间:\(CMTimeGetSeconds(currentT)), 找到的音频:\(recordedAudio.startTime), \(recordedAudio.endTime), \(recordedAudio.wavFilePath ?? "")")
|
|
|
+ BFLog(1, message: "当前时间:\(CMTimeGetSeconds(currentT)), 找到的音频:\(recordedAudio.startCMTime.seconds) ~ \(recordedAudio.endCMTime.seconds), \(recordedAudio.wavFilePath ?? "")")
|
|
|
|
|
|
// 创建播放器
|
|
|
if recordPlayer == nil || (recordPlayer?.currentItem?.asset as? AVURLAsset)?.url.lastPathComponent != (recordedAudio.wavFilePath as NSString?)?.lastPathComponent {
|
|
@@ -1354,11 +1373,11 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
guard let sself = self else {
|
|
|
return
|
|
|
}
|
|
|
- BFLog(1, message: "判断是否开始录音播放** hadPrepareToPlayRecord:\(hadPrepareToPlayRecord), currentPlayRecordIndex:\(currentPlayRecordIndex), isNormalPlaying :\(sself.isNormalPlaying),\(recordPlayer?.currentItem?.duration.timescale ?? 0),\(CMTimeGetSeconds(currentT) >= recordedAudio.startTime),\(CMTimeGetSeconds(currentT) <= recordedAudio.endTime - 0.2)")
|
|
|
+ BFLog(1, message: "判断是否开始录音播放** hadPrepareToPlayRecord:\(hadPrepareToPlayRecord), currentPlayRecordIndex:\(currentPlayRecordIndex), isNormalPlaying :\(sself.isNormalPlaying),\(recordPlayer?.currentItem?.duration.timescale ?? 0),\(CMTimeGetSeconds(currentT) >= recordedAudio.startCMTime.seconds),\(CMTimeGetSeconds(currentT) <= recordedAudio.endCMTime.seconds - 0.2)")
|
|
|
|
|
|
if !hadPrepareToPlayRecord,
|
|
|
- CMTimeGetSeconds(currentT) >= (recordedAudio.startTime - 0.1),
|
|
|
- CMTimeGetSeconds(currentT) <= recordedAudio.endTime - 0.2 // 这个条件是避免录音结束后有小幅度回退导致播放最新录音
|
|
|
+ CMTimeGetSeconds(currentT) >= (recordedAudio.startCMTime.seconds - 0.1),
|
|
|
+ CMTimeGetSeconds(currentT) <= recordedAudio.endCMTime.seconds - 0.2 // 这个条件是避免录音结束后有小幅度回退导致播放最新录音
|
|
|
{
|
|
|
if itemModels[currItemModelIndex].mediaType == .VIDEO, recordPlayer?.currentItem?.duration.timescale == 0 {
|
|
|
return
|
|
@@ -1366,7 +1385,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
// 应当开始播放了
|
|
|
// 两个逻辑:如果在播,则跳过;如果暂停拖动到中间,则seek
|
|
|
if currentPlayRecordIndex == -1, sself.isNormalPlaying {
|
|
|
- let second = CMTimeGetSeconds(currentT) - recordedAudio.startTime
|
|
|
+ let second = CMTimeGetSeconds(currentT) - recordedAudio.startCMTime.seconds
|
|
|
sself.assetPlayer?.volume = sself.haveSpeakVolume
|
|
|
|
|
|
DispatchQueue.main.async { [weak sself] in
|
|
@@ -1395,18 +1414,18 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
/// - recordedAudio: <#recordedAudio description#>
|
|
|
func imageMaterialRecordPlay(at currentT: CMTime, shouldPlayRecordIndex _: Int, recordedAudio: PQVoiceModel) {
|
|
|
synced(currentPlayRecordIndex) { [weak self] in
|
|
|
- guard let sself = self else {
|
|
|
+ guard let sself = self, sself.isNormalPlaying else {
|
|
|
return
|
|
|
}
|
|
|
- BFLog(1, message: "判断是否开始录音播放** hadPrepareToPlayRecord:\(hadPrepareToPlayRecord), currentPlayRecordIndex:\(currentPlayRecordIndex), isNormalPlaying :\(sself.isNormalPlaying),\(recordPlayer?.currentItem?.duration.timescale ?? 0),\(CMTimeGetSeconds(currentT) >= recordedAudio.startTime),\(CMTimeGetSeconds(currentT) <= recordedAudio.endTime - 0.2)")
|
|
|
+ BFLog(1, message: "判断是否开始录音播放** hadPrepareToPlayRecord:\(hadPrepareToPlayRecord), currentPlayRecordIndex:\(currentPlayRecordIndex), isNormalPlaying :\(sself.isNormalPlaying),\(recordPlayer?.currentItem?.duration.timescale ?? 0),\(CMTimeGetSeconds(currentT) >= recordedAudio.startCMTime.seconds),\(CMTimeGetSeconds(currentT) <= recordedAudio.endCMTime.seconds - 0.2)")
|
|
|
|
|
|
- if CMTimeGetSeconds(currentT) >= (recordedAudio.startTime - 0.1),
|
|
|
- CMTimeGetSeconds(currentT) <= recordedAudio.endTime // 这个条件是避免录音结束后有小幅度回退导致播放最新录音
|
|
|
+ if CMTimeGetSeconds(currentT) >= (recordedAudio.startCMTime.seconds - 0.1),
|
|
|
+ CMTimeGetSeconds(currentT) <= recordedAudio.endCMTime.seconds // 这个条件是避免录音结束后有小幅度回退导致播放最新录音
|
|
|
{
|
|
|
// 应当开始播放了
|
|
|
// 两个逻辑:如果在播,则跳过;如果暂停拖动到中间,则seek
|
|
|
if sself.isNormalPlaying {
|
|
|
- let second = CMTimeGetSeconds(currentT) - recordedAudio.startTime
|
|
|
+ let second = CMTimeGetSeconds(currentT) - recordedAudio.startCMTime.seconds
|
|
|
sself.assetPlayer?.volume = sself.haveSpeakVolume
|
|
|
|
|
|
DispatchQueue.main.async { [weak sself] in
|
|
@@ -1602,17 +1621,19 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
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 {
|
|
|
+ if su { // 不拖动,正常播放和录音时更新进度条
|
|
|
self?.progressThumV.progress = time.seconds
|
|
|
}
|
|
|
// 更新字幕
|
|
|
- self?.updateSubtitle(time: time)
|
|
|
+ if !(self?.isRecording ?? false) {
|
|
|
+ self?.updateSubtitle(time: time)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if isRecording {
|
|
|
- let startTime = recorderManager?.voiceModel?.startTime ?? 0
|
|
|
+ let startTime = recorderManager?.voiceModel?.startCMTime.seconds ?? 0
|
|
|
let progress = currentAssetProgress.seconds - startTime // - ratioX
|
|
|
// 使用播放器的进度来画线,因为进度是跟着播放器来了
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
@@ -1663,9 +1684,9 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
if itemModels[currItemModelIndex].mediaType == .VIDEO {
|
|
|
let duration = itemModels[currItemModelIndex].materialDuraion
|
|
|
if duration > 0 {
|
|
|
- currentAssetProgress = CMTime(value: CMTimeValue(newProgress * Float(duration) * 1000), timescale: 1000)
|
|
|
+ currentAssetProgress = CMTime(seconds: Double(newProgress) * duration, preferredTimescale: 1000)
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
- BFLog(message: "更新录音进度\(#function)-\(self?.currentAssetProgress.seconds ?? 0)")
|
|
|
+ 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
|
|
@@ -1674,7 +1695,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
} else {
|
|
|
currentAssetProgress = isBack ? CMTime(value: CMTimeValue(newProgress * 1000), timescale: 1000) : CMTime(value: CMTimeValue(newProgress * Float(itemModels[currItemModelIndex].materialDuraion) * 1000), timescale: 1000)
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
- BFLog(message: "更新录音进度\(#function)-\(self?.currentAssetProgress.seconds ?? 0)")
|
|
|
+ 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)")
|
|
@@ -1700,7 +1721,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
// 注:视频无法以录制进度驱动,因当录音开始录音时播放器还未播放,导致进度不一致
|
|
|
// 注:在录制停止时,视频播放器进度依然在走,误差在80毫秒左右
|
|
|
if isRecording, itemModels[currItemModelIndex].mediaType == .IMAGE {
|
|
|
- let startTime = recorderManager?.voiceModel?.startTime ?? 0
|
|
|
+ let startTime = recorderManager?.voiceModel?.startCMTime.seconds ?? 0
|
|
|
// 使用播放器的进度来画线,因为进度是跟着播放器来了
|
|
|
indirectionView?.setProgress(start: startTime, progress: progress)
|
|
|
}
|
|
@@ -1897,7 +1918,7 @@ public extension BFRecordScreenController {
|
|
|
}, 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) {
|
|
|
+ if (self?.itemModels[self?.currItemModelIndex ?? 0].voiceStickers.count ?? 0) <= ((recordInfo?.0 ?? 0) + 1) || (recordInfo?.1.endCMTime.seconds ?? 0) >= (self?.itemModels[self?.currItemModelIndex ?? 0].voiceStickers.last?.endCMTime.seconds ?? 0) {
|
|
|
self?.isEndPlay = true
|
|
|
self?.pause()
|
|
|
// 注:矫正进度--播放结束后当前指针应该到当前素材总时长
|
|
@@ -1907,7 +1928,7 @@ public extension BFRecordScreenController {
|
|
|
self?.recordBtn.isHidden = false
|
|
|
} else {
|
|
|
// 注:矫正进度--一段录音播放结束后当前指针应该到当前录音结束点
|
|
|
- self?.currentAssetProgress = CMTime(seconds: self?.itemModels[self?.currItemModelIndex ?? 0].voiceStickers[(recordInfo?.0 ?? 0) + 1].startTime ?? 0, preferredTimescale: 1000)
|
|
|
+ self?.currentAssetProgress = CMTime(seconds: self?.itemModels[self?.currItemModelIndex ?? 0].voiceStickers[(recordInfo?.0 ?? 0) + 1].startCMTime.seconds ?? 0, preferredTimescale: 1000)
|
|
|
self?.startPlayRecord(time: self?.currentAssetProgress ?? CMTime.zero)
|
|
|
}
|
|
|
}
|
|
@@ -1923,7 +1944,7 @@ public extension BFRecordScreenController {
|
|
|
/// 处理图片素材录音
|
|
|
func imageRecordProgress(isRecord: Bool = false, progress: Float64) {
|
|
|
if isRecord {
|
|
|
- currentAssetProgress = CMTime(seconds: (recorderManager?.voiceModel?.startTime ?? 0) + progress, preferredTimescale: 1000)
|
|
|
+ currentAssetProgress = CMTime(seconds: (recorderManager?.voiceModel?.startCMTime.seconds ?? 0) + progress, preferredTimescale: 1000)
|
|
|
} else {
|
|
|
currentAssetProgress = CMTime(seconds: recordStartPlayTime.seconds + progress, preferredTimescale: 1000)
|
|
|
}
|