|
@@ -914,18 +914,13 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
model.endCMTime = wself.currentAssetProgress
|
|
|
// BFLog(1, message: "录音地址:\((model.wavFilePath ?? "").replacingOccurrences(of: documensDirectory, with: ""))")
|
|
|
BFLog(1, message: " 文件时长record:\(wself.rscmanager.recordItem?.voiceStickers.count ?? 0), \(model.startCMTime.seconds) -- \(model.endCMTime.seconds), dur: \(model.endCMTime.seconds - model.startCMTime.seconds)")
|
|
|
-
|
|
|
- if model.endCMTime.seconds < model.startCMTime.seconds{
|
|
|
- BFLog(1, message: "error")
|
|
|
- }
|
|
|
+ wself.recordFinished((model.endCMTime.seconds - model.startCMTime.seconds) >= 1)
|
|
|
+
|
|
|
/// 注:录音机回调的录音时长大于一秒,而业务逻辑计算的会小于一秒
|
|
|
if (model.endCMTime.seconds - model.startCMTime.seconds) < 1 {
|
|
|
// 取消录制
|
|
|
- wself.recordManagerCancelRecord(voiceModel: model)
|
|
|
- wself.rscurrentManager.recordFinished(isSuccess: false)
|
|
|
return
|
|
|
}
|
|
|
- wself.rscurrentManager.recordFinished(isSuccess:true)
|
|
|
// ********** 开始处理冲突的录制部分
|
|
|
let newRange = CMTimeRange(start: model.startCMTime, end: model.endCMTime)
|
|
|
|
|
@@ -950,7 +945,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
|
|
|
wself.itemModels[wself.currItemModelIndex].voiceStickers.append(model)
|
|
|
- // 录制结束回调
|
|
|
+ // 录制结束回调给主工程页面(埋点之类功能)
|
|
|
wself.recordEndHandle?(model)
|
|
|
// 如果是图片素材同时有需要删除的录音时需要调整录音文件开始结束时间
|
|
|
// warning: 图片录制的时候应该只能在结尾处录制
|
|
@@ -1588,15 +1583,8 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
events.removeLast()
|
|
|
|
|
|
let dur = itemModels[currItemModelIndex].materialDuraion.seconds
|
|
|
- if dur > 0 {
|
|
|
- if currMediaType == .Image {
|
|
|
- changeProgress(isBack: true, progress: Float(jumpTime.seconds))
|
|
|
- } else {
|
|
|
- changeProgress(changCMTime: jumpTime)
|
|
|
- }
|
|
|
- } else {
|
|
|
- changeProgress(progress: Float(0))
|
|
|
- }
|
|
|
+ changeProgress(changCMTime: (dur > 0) ? jumpTime : .zero)
|
|
|
+
|
|
|
isDragingProgressSlder = false
|
|
|
currentPlayRecordIndex = -1
|
|
|
BFLog(3, message: "重置播放index-\(#function) = \(currentPlayRecordIndex)")
|
|
@@ -1657,9 +1645,8 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
|
|
|
// MARK: - 进度条拖动回调
|
|
|
-
|
|
|
- func thumbViewEnded(progress: Float) {
|
|
|
- changeProgress(progress: progress)
|
|
|
+ func thumbViewDragEnded(progress: Float) {
|
|
|
+ changeProgress(changCMTime: convertProgressToCMTime(progress))
|
|
|
isDragingProgressSlder = false
|
|
|
currentPlayRecordIndex = -1
|
|
|
hadPrepareToPlayRecord = false
|
|
@@ -1693,7 +1680,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
wself.isDragingProgressSlder = true
|
|
|
|
|
|
- wself.changeProgress(progress: process)
|
|
|
+ wself.changeProgress(changCMTime: wself.convertProgressToCMTime(process))
|
|
|
|
|
|
if wself.currMediaType != .Video && CMTimeCompare(wself.rscurrentManager.recordItem?.materialDuraion ?? .zero, .zero) != 0 {
|
|
|
wself.recordBtn.isHidden = true
|
|
@@ -1706,7 +1693,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
guard let wself = self else { return }
|
|
|
|
|
|
- wself.thumbViewEnded(progress: process)
|
|
|
+ wself.thumbViewDragEnded(progress: process)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1745,33 +1732,39 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
if startTime != nil && endTime != nil {
|
|
|
// TODO: 停在了录音区间,显示删除按钮
|
|
|
- if needAdsorb {
|
|
|
- if fabs((endTime! - currentAssetProgress).seconds) < 0.5 {
|
|
|
- BFLog(1, message: "吸附在录音结尾, \(endTime!.seconds)")
|
|
|
- // changeWithDrawBtnLayout(false)
|
|
|
- changeProgress(changCMTime: endTime!)
|
|
|
- progressThumV.progress = endTime!.seconds
|
|
|
-
|
|
|
- searchStopAtRecordRange(needAdsorb: false)
|
|
|
- return
|
|
|
- } else {
|
|
|
- if fabs((startTime! - currentAssetProgress).seconds) < 0.5 {
|
|
|
- BFLog(1, message: "吸附在录音开始")
|
|
|
- // changeWithDrawBtnLayout(true)
|
|
|
- changeProgress(changCMTime: startTime!)
|
|
|
- progressThumV.progress = startTime!.seconds
|
|
|
- }
|
|
|
- deleteRecordBtn.isHidden = false
|
|
|
- recordBtn.isHidden = true
|
|
|
- // add by ak 这里 isHidden 无效
|
|
|
-
|
|
|
- BFLog(1, message: "停在了录音区间里 \(isStopAtRecordRange), currTime:\(currentAssetProgress.seconds), 录音范围:\(startTime!.seconds) - \(endTime!.seconds)")
|
|
|
- }
|
|
|
- } else {
|
|
|
- updateRecordBtnStatus(true)
|
|
|
+// if needAdsorb {
|
|
|
+// if fabs((endTime! - currentAssetProgress).seconds) < 0.5 {
|
|
|
+// BFLog(1, message: "吸附在录音结尾, \(endTime!.seconds)")
|
|
|
+// // changeWithDrawBtnLayout(false)
|
|
|
+// changeProgress(changCMTime: endTime!)
|
|
|
+// progressThumV.progress = endTime!.seconds
|
|
|
+//
|
|
|
+// searchStopAtRecordRange(needAdsorb: false)
|
|
|
+// return
|
|
|
+// } else {
|
|
|
+// if fabs((startTime! - currentAssetProgress).seconds) < 0.5 {
|
|
|
+// BFLog(1, message: "吸附在录音开始")
|
|
|
+// // changeWithDrawBtnLayout(true)
|
|
|
+// changeProgress(changCMTime: startTime!)
|
|
|
+// progressThumV.progress = startTime!.seconds
|
|
|
+// }
|
|
|
+// deleteRecordBtn.isHidden = false
|
|
|
+// recordBtn.isHidden = true
|
|
|
+// // add by ak 这里 isHidden 无效
|
|
|
+//
|
|
|
+// BFLog(1, message: "停在了录音区间里 \(isStopAtRecordRange), currTime:\(currentAssetProgress.seconds), 录音范围:\(startTime!.seconds) - \(endTime!.seconds)")
|
|
|
+// }
|
|
|
+// } else {
|
|
|
|
|
|
BFLog(1, message: "停在了录音区间里 \(isStopAtRecordRange), currTime:\(currentAssetProgress.seconds), 录音范围:\(startTime!.seconds) - \(endTime!.seconds)")
|
|
|
+// }
|
|
|
+ // 摄像和图片都可以走插入录制功能
|
|
|
+ if (currMediaType == .Camera && (endTime! - currentAssetProgress).seconds < 1.5 * 5 / 70.0)
|
|
|
+ || (currMediaType == .Image && ((endTime! - currentAssetProgress).seconds < 1.5 * 2.0 / 70.0)){
|
|
|
+ canInsertVideo = true
|
|
|
+ BFLog(1, message: "可以插入录音")
|
|
|
}
|
|
|
+ updateRecordBtnStatus(true)
|
|
|
|
|
|
} else {
|
|
|
updateRecordBtnStatus(false)
|
|
@@ -1813,6 +1806,25 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
deleteRecordBtn.isHidden = isEndPlay ? true : !(recordBtn.isHidden)
|
|
|
}
|
|
|
+
|
|
|
+ func recordFinished(_ isFinished:Bool) {
|
|
|
+ if !isFinished {
|
|
|
+ recordManagerCancelRecord(voiceModel: recorderManager?.voiceModel)
|
|
|
+ rscurrentManager.recordFinished(isSuccess: false)
|
|
|
+ }else {
|
|
|
+ rscurrentManager.recordFinished(isSuccess:true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //
|
|
|
+ func recoverRecord() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 重新加载数据
|
|
|
+ func reloadData(){
|
|
|
+ // 重置播放器进度,按钮状态,缩略图展示,当前进度
|
|
|
+ }
|
|
|
|
|
|
// MARK: - 权限申请
|
|
|
|
|
@@ -2281,22 +2293,30 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
withDrawBtn.setNeedsLayout()
|
|
|
withDrawBtn.layoutIfNeeded()
|
|
|
}
|
|
|
-
|
|
|
- // 通过缩略图进度条控制播放进度
|
|
|
- // progress : 图片且isback为true时,表示是时长; 其他情况: 0 - 1,百分比
|
|
|
- func changeProgress(isBack: Bool = false, progress: Float = -1, changCMTime: CMTime = .zero) {
|
|
|
+
|
|
|
+ func convertProgressToCMTime (_ progress:Float) -> CMTime {
|
|
|
var newProgress = progress
|
|
|
if progress.isNaN || progress.isInfinite {
|
|
|
newProgress = 0
|
|
|
}
|
|
|
+
|
|
|
+ var currTime = CMTime.zero
|
|
|
+ let duration = itemModels[currItemModelIndex].materialDuraion
|
|
|
+
|
|
|
+ currTime = CMTime(seconds: Double(newProgress) * duration.seconds, preferredTimescale: 1000)
|
|
|
+
|
|
|
+
|
|
|
+ return currTime
|
|
|
+ }
|
|
|
+
|
|
|
+ // 通过缩略图进度条控制播放进度
|
|
|
+ // progress : 图片且isback为true时,表示是时长; 其他情况: 0 - 1,百分比
|
|
|
+ func changeProgress(changCMTime: CMTime = .zero) {
|
|
|
+
|
|
|
if currMediaType == .Video {
|
|
|
let duration = itemModels[currItemModelIndex].materialDuraion
|
|
|
if duration.seconds > 0 {
|
|
|
- if progress == -1 {
|
|
|
- rscurrentManager.currentAssetProgress = changCMTime
|
|
|
- } else {
|
|
|
- rscurrentManager.currentAssetProgress = CMTime(seconds: Double(newProgress) * duration.seconds, preferredTimescale: 1000)
|
|
|
- }
|
|
|
+ rscurrentManager.currentAssetProgress = changCMTime
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
guard let wself = self else { return }
|
|
|
|
|
@@ -2319,7 +2339,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
- rscurrentManager.currentAssetProgress = isBack ? CMTime(seconds: Double(newProgress), preferredTimescale: 1000) : ((progress != -1) ? CMTime(seconds: (Double(newProgress) * itemModels[currItemModelIndex].materialDuraion.seconds), preferredTimescale: 1000) : changCMTime)
|
|
|
+ rscurrentManager.currentAssetProgress = changCMTime
|
|
|
if currentAssetProgress.seconds > itemModels[currItemModelIndex].materialDuraion.seconds {
|
|
|
rscurrentManager.currentAssetProgress = itemModels[currItemModelIndex].materialDuraion
|
|
|
}
|
|
@@ -2329,7 +2349,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
// BFLog(1,message: "更新进度- \(wself.currentAssetProgress.seconds)")
|
|
|
wself.progreddL.text = String(format: "%@", CMTimeGetSeconds(self!.currentAssetProgress).formatDurationToHMS())
|
|
|
}
|
|
|
- BFLog(message: "progress = \(progress),currentAssetProgress = \(currentAssetProgress.seconds),materialDuraion = \(itemModels[currItemModelIndex].materialDuraion.seconds)")
|
|
|
+ BFLog(message: "currentAssetProgress = \(currentAssetProgress.seconds),materialDuraion = \(itemModels[currItemModelIndex].materialDuraion.seconds)")
|
|
|
|
|
|
// add by ak 图片素材拖动指针时同时更新字幕显现数据
|
|
|
updateSubtitle(time: currentAssetProgress)
|