|
@@ -21,7 +21,7 @@ import UIKit
|
|
|
struct WithDrawModel {
|
|
|
var type: Int // 0:拖动; 1:预览播放暂停 2: 录音结束 3: 删除录音
|
|
|
var timestamp: CMTime
|
|
|
- var deletedVoices: [(PQVoiceModel, Int)]?
|
|
|
+ var deletedVoices: [PQVoiceModel]?
|
|
|
// add by ak 保存删除的字幕数据用于恢复
|
|
|
var deletedTittles: [PQEditSubTitleModel]?
|
|
|
//
|
|
@@ -877,21 +877,21 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
// ********** 开始处理冲突的录制部分
|
|
|
let newRange = CMTimeRange(start: model.startCMTime, end: model.endCMTime)
|
|
|
|
|
|
- var deletedVoices = [(PQVoiceModel, Int)]()
|
|
|
+ var deletedVoices = [PQVoiceModel]()
|
|
|
// 要删除的字幕
|
|
|
var deletedTitlesTemp = [PQEditSubTitleModel]()
|
|
|
|
|
|
// 查找要删除的音频和字幕数据
|
|
|
- for (i, m) in wself.itemModels[wself.currItemModelIndex].voiceStickers.enumerated() {
|
|
|
+ for m in wself.itemModels[wself.currItemModelIndex].voiceStickers {
|
|
|
let originRange = CMTimeRange(start: m.startCMTime, end: CMTime(seconds: m.endCMTime.seconds - 0.02, preferredTimescale: 1000))
|
|
|
if CMTimeRangeGetIntersection(originRange, otherRange: newRange).duration.seconds > 0 {
|
|
|
- deletedVoices.append((m, i))
|
|
|
+ deletedVoices.append(m)
|
|
|
deletedTitlesTemp += wself.deleteTitles(voiceModel: m)
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
// 删除冲突的音频
|
|
|
- deletedVoices.forEach { m, _ in
|
|
|
+ deletedVoices.forEach { m in
|
|
|
wself.itemModels[wself.currItemModelIndex].voiceStickers.removeAll { tempM in
|
|
|
m.wavFilePath == tempM.wavFilePath
|
|
|
}
|
|
@@ -963,7 +963,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
// 矫正进度
|
|
|
wself.resetCurrentProgress()
|
|
|
wself.deleteRecordBtn.isHidden = true
|
|
|
- wself.recordBtn.isHidden = (wself.currMediaType != .Video && (wself.isEndPlay )) ? false : (wself.isEndPlay ?? false)
|
|
|
+ wself.recordBtn.isHidden = (wself.currMediaType != .Video && (wself.isEndPlay )) ? false : (wself.isEndPlay )
|
|
|
}
|
|
|
wself.currentPlayRecordIndex = -3 // 刚录音完,不需要播放录音
|
|
|
BFLog(3, message: "重置播放index-\(#function) = \(wself.currentPlayRecordIndex)")
|
|
@@ -1194,43 +1194,12 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
let model = itemModels[currItemModelIndex].voiceStickers[isStopAtRecordRange]
|
|
|
itemModels[currItemModelIndex].voiceStickers.remove(at: isStopAtRecordRange)
|
|
|
indirectionView?.deleteItem(index: isStopAtRecordRange)
|
|
|
- var event = WithDrawModel(type: 3, timestamp: currentAssetProgress, deletedVoices: [(model, isStopAtRecordRange)])
|
|
|
+ var event = WithDrawModel(type: 3, timestamp: currentAssetProgress, deletedVoices: [model])
|
|
|
event.deletedTittles = deleteTitles(voiceModel: model)
|
|
|
events.append(event)
|
|
|
|
|
|
rscurrentManager.deleteRecord(at: currentAssetProgress)
|
|
|
|
|
|
- // 注:删除录音后图片素材需要回撤指针进度,同时后面录音往前挪
|
|
|
- if currMediaType == .Image {
|
|
|
- let currDuration = model.endCMTime - model.startCMTime
|
|
|
- itemModels[currItemModelIndex].materialDuraion = itemModels[currItemModelIndex].materialDuraion - currDuration
|
|
|
- rscurrentManager.currentAssetProgress = model.startCMTime
|
|
|
-
|
|
|
- // 更新进度
|
|
|
- resetCurrentProgress()
|
|
|
- for (index, item) in itemModels[currItemModelIndex].voiceStickers.enumerated() {
|
|
|
- if index >= isStopAtRecordRange {
|
|
|
- // 注:开始时间减去duration or 等一前一段录音的结束时间
|
|
|
- item.startCMTime = item.startCMTime - currDuration
|
|
|
- item.endCMTime = item.endCMTime - currDuration
|
|
|
-
|
|
|
- let titlsList = itemModels[currItemModelIndex].titleStickers.filter { tm in
|
|
|
- tm.recordId == item.recordId
|
|
|
- }
|
|
|
-
|
|
|
- for titleM in titlsList {
|
|
|
- titleM.timelineIn = titleM.timelineIn - currDuration
|
|
|
- titleM.timelineOut = titleM.timelineOut - currDuration
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- /// 重绘录音进度视图
|
|
|
- resetAllIndirectionView()
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
rscurrentManager.changeRecordMaterail()
|
|
|
|
|
|
if currMediaType != .Video{
|
|
@@ -1428,20 +1397,18 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
|
|
|
// 恢复被覆盖的音频
|
|
|
- var tuples = action.deletedVoices
|
|
|
- if tuples != nil, tuples!.count > 0 {
|
|
|
- tuples!.sort { tuple1, tuple2 in
|
|
|
- tuple1.1 < tuple2.1
|
|
|
- }
|
|
|
- tuples?.forEach { tuple in
|
|
|
- itemModels[currItemModelIndex].voiceStickers.insert(tuple.0, at: tuple.1)
|
|
|
+ if let voiceTuples = action.deletedVoices{
|
|
|
+ itemModels[currItemModelIndex].voiceStickers.append(contentsOf: voiceTuples)
|
|
|
+ itemModels[currItemModelIndex].voiceStickers.sort { m1, m2 in
|
|
|
+ CMTimeCompare(m1.startCMTime, m2.startCMTime) < 0
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
// 恢复被覆盖的字幕
|
|
|
- let titleTuples = action.deletedTittles
|
|
|
- if titleTuples != nil, titleTuples!.count > 0 {
|
|
|
- titleTuples?.forEach { titleTuple in
|
|
|
- itemModels[currItemModelIndex].titleStickers.append(titleTuple)
|
|
|
+ if let titleTuples = action.deletedTittles{
|
|
|
+ itemModels[currItemModelIndex].titleStickers.append(contentsOf: titleTuples)
|
|
|
+ itemModels[currItemModelIndex].titleStickers.sort { m1, m2 in
|
|
|
+ CMTimeCompare(m1.timelineOut, m2.timelineOut) < 0
|
|
|
}
|
|
|
}
|
|
|
// jumpTime = model.startCMTime.seconds
|
|
@@ -1456,42 +1423,81 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
} else if action.type == 3 {
|
|
|
// 恢复删除录音
|
|
|
- var tuples = action.deletedVoices
|
|
|
- tuples?.sort { tuple1, tuple2 in
|
|
|
- tuple1.1 < tuple2.1
|
|
|
- }
|
|
|
- if currMediaType == .Video {
|
|
|
- tuples?.forEach { tuple in
|
|
|
- itemModels[currItemModelIndex].voiceStickers.insert(tuple.0, at: tuple.1)
|
|
|
- }
|
|
|
- } else {
|
|
|
- tuples?.forEach { tuple in
|
|
|
- itemModels[currItemModelIndex].voiceStickers.insert(tuple.0, at: tuple.1)
|
|
|
- let currDuration = tuple.0.endCMTime - tuple.0.startCMTime
|
|
|
- itemModels[currItemModelIndex].materialDuraion = itemModels[currItemModelIndex].materialDuraion + currDuration
|
|
|
- for (index, item) in itemModels[currItemModelIndex].voiceStickers.enumerated() {
|
|
|
- if index > tuple.1 {
|
|
|
- // 注:之后的录音和字幕增加对应的时长
|
|
|
- item.startCMTime = item.startCMTime + currDuration
|
|
|
- item.endCMTime = item.endCMTime + currDuration
|
|
|
+ if var tuples = action.deletedVoices{
|
|
|
+
|
|
|
+ if currMediaType != .Video {
|
|
|
|
|
|
+ tuples.sort { m1, m2 in
|
|
|
+ CMTimeCompare(m1.startCMTime, m2.startCMTime) < 0
|
|
|
+ }
|
|
|
+
|
|
|
+ if let first = tuples.first, let end = tuples.last {
|
|
|
+ let currDuration = end.endCMTime - first.startCMTime
|
|
|
+ itemModels[currItemModelIndex].materialDuraion = itemModels[currItemModelIndex].materialDuraion + currDuration
|
|
|
+
|
|
|
+ // 恢复录音的时间点
|
|
|
+ let list = itemModels[currItemModelIndex].voiceStickers.filter({ mod in
|
|
|
+ CMTimeCompare(mod.startCMTime, first.startCMTime) >= 0
|
|
|
+ })
|
|
|
+
|
|
|
+ list.forEach { mod in
|
|
|
+ mod.startCMTime = mod.startCMTime + currDuration
|
|
|
+ mod.endCMTime = mod.endCMTime + currDuration
|
|
|
+
|
|
|
+ // 恢复字幕的时间点
|
|
|
let titlsList = itemModels[currItemModelIndex].titleStickers.filter { tm in
|
|
|
- tm.recordId == item.recordId
|
|
|
+ tm.recordId == mod.recordId
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
for titleM in titlsList {
|
|
|
titleM.timelineIn = titleM.timelineIn + currDuration
|
|
|
titleM.timelineOut = titleM.timelineOut + currDuration
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if currMediaType == .Camera {
|
|
|
+ // 恢复录像的时间点
|
|
|
+ _ = itemModels[currItemModelIndex].videoStickers.map { mod in
|
|
|
+ if CMTimeCompare(mod.timelineCMIn, first.startCMTime) >= 0{
|
|
|
+ mod.timelineCMIn = mod.timelineCMIn + currDuration
|
|
|
+ mod.timelineCMOut = mod.timelineCMOut + currDuration
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 摄像头录制的
|
|
|
+ if let videoTuple = action.deletedCameras {
|
|
|
+ itemModels[currItemModelIndex].videoStickers.append(contentsOf: videoTuple)
|
|
|
+ itemModels[currItemModelIndex].videoStickers.sort { m1, m2 in
|
|
|
+ CMTimeCompare(m1.timelineCMIn, m2.timelineCMIn) < 0
|
|
|
+ }
|
|
|
+ itemModels[currItemModelIndex].thumbImgs.removeAll()
|
|
|
+ itemModels[currItemModelIndex].videoStickers.forEach { mod in
|
|
|
+ if let thumImag = mod.thumImgs{
|
|
|
+ itemModels[currItemModelIndex].thumbImgs.append(contentsOf: thumImag)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ DispatchQueue.main.async {[weak self] in
|
|
|
+ guard let wself = self else { return }
|
|
|
+
|
|
|
+ wself.rscmanager.cameraProgressV?.collectionV.reloadData()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ itemModels[currItemModelIndex].voiceStickers.append(contentsOf: tuples)
|
|
|
+ itemModels[currItemModelIndex].voiceStickers.sort { m1, m2 in
|
|
|
+ CMTimeCompare(m1.startCMTime, m2.startCMTime) < 0
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
// 恢复字幕
|
|
|
- let titleTuples = action.deletedTittles
|
|
|
- if titleTuples != nil, titleTuples!.count > 0 {
|
|
|
- titleTuples?.forEach { titleTuple in
|
|
|
- itemModels[currItemModelIndex].titleStickers.append(titleTuple)
|
|
|
+
|
|
|
+ if let titleTuples = action.deletedTittles, titleTuples.count > 0 {
|
|
|
+ itemModels[currItemModelIndex].titleStickers.append(contentsOf: titleTuples)
|
|
|
+ itemModels[currItemModelIndex].titleStickers.sort { m1, m2 in
|
|
|
+ CMTimeCompare(m1.timelineOut, m2.timelineOut) < 0
|
|
|
}
|
|
|
}
|
|
|
if currMediaType == .Image {
|