|
@@ -32,6 +32,8 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
public var assets = [PHAsset]()
|
|
|
var currItemModelIndex = 0
|
|
|
+ // 当前图片录音播放位置
|
|
|
+ var currImagePlayIndex = 0
|
|
|
public var itemModels = [BFRecordItemModel]()
|
|
|
// add by ak 当前的显示的字幕位置
|
|
|
var showSubtitleIndex = 0
|
|
@@ -63,39 +65,40 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- var currentAssetProgress: CMTime = .zero // 当前素材播放的进度
|
|
|
- var recordStartTime: Double = 0 // 录制开始时间
|
|
|
- var pauseTime : Double = 0 // 停止无操作的时间点
|
|
|
+ var currentAssetProgress: CMTime = .zero // 当前素材播放的进度
|
|
|
+ var recordStartTime: Double = 0 // 录制开始时间
|
|
|
+ var pauseTime: Double = 0 // 停止无操作的时间点
|
|
|
|
|
|
- var assetPlayer: AVPlayer? // 原视频音频播放器
|
|
|
+ var assetPlayer: AVPlayer? // 原视频音频播放器
|
|
|
|
|
|
- var hadPrepareToPlayRecord = false // 录音播放器准备
|
|
|
- var recordPlayer : AVPlayer? // 录音音频播放器
|
|
|
- var movie : GPUImageMovie? // 视频预览
|
|
|
- var playView : GPUImageView? // 视频展示视图
|
|
|
+ var hadPrepareToPlayRecord = false // 录音播放器准备
|
|
|
+ var recordPlayer: AVPlayer? // 录音音频播放器
|
|
|
+ var movie: GPUImageMovie? // 视频预览
|
|
|
+ var playView: GPUImageView? // 视频展示视图
|
|
|
|
|
|
// MARK: 行为参数
|
|
|
+
|
|
|
var movieIsProcessing = false
|
|
|
- var events = [WithDrawModel]() // 行为记录,方便撤销
|
|
|
- var isDragingProgressSlder : Bool = false // 是否在拖动进度条
|
|
|
+ var events = [WithDrawModel]() // 行为记录,方便撤销
|
|
|
+ var isDragingProgressSlder: Bool = false // 是否在拖动进度条
|
|
|
var isStopAtRecordRange = -1
|
|
|
|
|
|
// 保存识别出来的字幕信息,用于回放,和合成使用
|
|
|
// var saveSubTitles:[PQEditSubTitleModel] = Array.init()
|
|
|
-
|
|
|
- //MARK: - 录音相关
|
|
|
+
|
|
|
+ // MARK: - 录音相关
|
|
|
|
|
|
// 定义音频的编码参数
|
|
|
- let recordSettings : [String: Any] = [AVSampleRateKey: 44100.0, // 声音采样率
|
|
|
+ let recordSettings: [String: Any] = [AVSampleRateKey: 44100.0, // 声音采样率
|
|
|
AVFormatIDKey: kAudioFormatLinearPCM, // 编码格式
|
|
|
AVNumberOfChannelsKey: 1, // 采集音轨
|
|
|
AVEncoderBitDepthHintKey: 16, // 位深
|
|
|
AVEncoderAudioQualityKey: AVAudioQuality.medium.rawValue] // 音频质量
|
|
|
|
|
|
- public var haveSpeakVolume : Float = 0.0
|
|
|
- public var noSpeakVolume : Float = 1.0
|
|
|
-
|
|
|
- lazy var recorderManager : BFVoiceRecordManager = {
|
|
|
+ public var haveSpeakVolume: Float = 0.0
|
|
|
+ public var noSpeakVolume: Float = 1.0
|
|
|
+
|
|
|
+ lazy var recorderManager: BFVoiceRecordManager = {
|
|
|
let manager = BFVoiceRecordManager()
|
|
|
manager.cancelRecordHandle = { _ in
|
|
|
}
|
|
@@ -121,7 +124,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
return CMTimeRangeGetIntersection(originRange, otherRange: newRange).duration.seconds > 0
|
|
|
}
|
|
|
BFLog(1, message: "添加录音文件:\(model.startTime) -- \(model.endTime)")
|
|
|
-
|
|
|
+
|
|
|
var event = sself.events.last
|
|
|
if event != nil {
|
|
|
event!.deletedVoices = deletedVoices
|
|
@@ -139,7 +142,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
model.endTime = sself.currentAssetProgress.seconds
|
|
|
self?.isEndPlay = true
|
|
|
}
|
|
|
- DispatchQueue.main.async {[weak self] in
|
|
|
+ DispatchQueue.main.async { [weak self] in
|
|
|
// 录音完,重绘撤销按钮,更新录音按钮,
|
|
|
self?.changeWithDrawBtnLayout(true)
|
|
|
// 注:在录制结束时矫正当前位置,避免跟指针无法对其
|
|
@@ -174,7 +177,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
return l
|
|
|
}()
|
|
|
|
|
|
- lazy var playBtn : UIButton = {
|
|
|
+ lazy var playBtn: UIButton = {
|
|
|
let btn = UIButton(frame: view.bounds)
|
|
|
btn.setImage(imageInRecordScreenKit(by: "preview_play"), for: .normal)
|
|
|
let vv = UIView(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
|
|
@@ -183,7 +186,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
return btn
|
|
|
}()
|
|
|
|
|
|
- lazy var bottomeView : UIImageView = {
|
|
|
+ lazy var bottomeView: UIImageView = {
|
|
|
let iv = UIImageView(image: imageInRecordScreenKit(by: "bottom_shadow"))
|
|
|
iv.contentMode = .scaleAspectFill
|
|
|
iv.isUserInteractionEnabled = true
|
|
@@ -197,11 +200,11 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
return iv
|
|
|
}()
|
|
|
|
|
|
- lazy var recordBtn : UIButton = {
|
|
|
+ lazy var recordBtn: UIButton = {
|
|
|
let btn = UIButton(type: .custom)
|
|
|
btn.backgroundColor = ThemeStyleColor
|
|
|
btn.setTitle("按住 说话", for: .normal)
|
|
|
- btn.addCorner(corner:6)
|
|
|
+ btn.addCorner(corner: 6)
|
|
|
btn.adjustsImageWhenHighlighted = false
|
|
|
btn.addTarget(self, action: #selector(startRecord), for: .touchDown)
|
|
|
btn.addTarget(self, action: #selector(endRecord), for: .touchUpInside)
|
|
@@ -209,18 +212,18 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
return btn
|
|
|
}()
|
|
|
|
|
|
- lazy var deleteRecordBtn : UIButton = {
|
|
|
+ lazy var deleteRecordBtn: UIButton = {
|
|
|
let btn = UIButton(type: .custom)
|
|
|
btn.backgroundColor = .red
|
|
|
btn.setTitle("删除录制", for: .normal)
|
|
|
btn.adjustsImageWhenHighlighted = false
|
|
|
- btn.addCorner(corner:6)
|
|
|
+ btn.addCorner(corner: 6)
|
|
|
btn.addTarget(self, action: #selector(deleteRecorded), for: .touchUpInside)
|
|
|
btn.isHidden = true
|
|
|
return btn
|
|
|
}()
|
|
|
|
|
|
- lazy var withDrawBtn : UIButton = {
|
|
|
+ lazy var withDrawBtn: UIButton = {
|
|
|
let btn = UIButton(type: .custom)
|
|
|
btn.setImage(imageInRecordScreenKit(by: "withdraw_n"), for: .normal)
|
|
|
btn.setImage(imageInRecordScreenKit(by: "withdraw_h"), for: .highlighted)
|
|
@@ -233,7 +236,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
return btn
|
|
|
}()
|
|
|
|
|
|
- lazy var changeVoiceBtn : UIButton = {
|
|
|
+ lazy var changeVoiceBtn: UIButton = {
|
|
|
let btn = UIButton(type: .custom)
|
|
|
btn.setImage(imageInRecordScreenKit(by: "changeVoice_n"), for: .normal)
|
|
|
btn.setImage(imageInRecordScreenKit(by: "changeVoice_h"), for: .highlighted)
|
|
@@ -246,7 +249,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
return btn
|
|
|
}()
|
|
|
|
|
|
- lazy var toolV : BFIntroduceToolView = {
|
|
|
+ lazy var toolV: BFIntroduceToolView = {
|
|
|
let toolV = BFIntroduceToolView()
|
|
|
toolV.centerY = view.centerY
|
|
|
|
|
@@ -263,14 +266,14 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}()
|
|
|
|
|
|
// 头像 add by ak
|
|
|
- lazy var avatarView : BFRecordAvatarView = {
|
|
|
+ lazy var avatarView: BFRecordAvatarView = {
|
|
|
let avatarView = BFRecordAvatarView(frame: CGRect(x: 10, y: 10, width: 120, height: 120))
|
|
|
avatarView.isHidden = true
|
|
|
return avatarView
|
|
|
}()
|
|
|
|
|
|
// 打开摄像头
|
|
|
- lazy var openCameraBtn : UIButton = {
|
|
|
+ lazy var openCameraBtn: UIButton = {
|
|
|
let btn = UIButton(type: .custom)
|
|
|
btn.setImage(imageInRecordScreenKit(by: "openCamera"), for: .normal)
|
|
|
btn.addTarget(self, action: #selector(openCamera), for: .touchUpInside)
|
|
@@ -278,7 +281,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}()
|
|
|
|
|
|
// 画笔
|
|
|
- lazy var drawPinBtn : UIButton = {
|
|
|
+ lazy var drawPinBtn: UIButton = {
|
|
|
let btn = UIButton(type: .custom)
|
|
|
btn.setImage(imageInRecordScreenKit(by: "drawPin"), for: .normal)
|
|
|
btn.addTarget(self, action: #selector(drawPin), for: .touchUpInside)
|
|
@@ -286,7 +289,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}()
|
|
|
|
|
|
// 字幕设置
|
|
|
- lazy var subtitleBtn : UIButton = {
|
|
|
+ lazy var subtitleBtn: UIButton = {
|
|
|
let btn = UIButton(type: .custom)
|
|
|
btn.setImage(imageInRecordScreenKit(by: "subtitleBtn"), for: .normal)
|
|
|
btn.addTarget(self, action: #selector(subTitleClick), for: .touchUpInside)
|
|
@@ -294,7 +297,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}()
|
|
|
|
|
|
// 声音设置
|
|
|
- lazy var soundSettingBtn : UIButton = {
|
|
|
+ lazy var soundSettingBtn: UIButton = {
|
|
|
let btn = UIButton(type: .custom)
|
|
|
btn.setImage(imageInRecordScreenKit(by: "soundBtn"), for: .normal)
|
|
|
btn.addTarget(self, action: #selector(soundSetting), for: .touchUpInside)
|
|
@@ -302,14 +305,14 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}()
|
|
|
|
|
|
// 字幕设置面板
|
|
|
- lazy var subtitleSettingView : BFSubtitleSettingView = {
|
|
|
+ lazy var subtitleSettingView: BFSubtitleSettingView = {
|
|
|
let subtitleSetting = BFSubtitleSettingView(frame: CGRect(x: 0, y: 0, width: cScreenWidth, height: cScreenHeigth))
|
|
|
subtitleSetting.isHidden = true
|
|
|
return subtitleSetting
|
|
|
}()
|
|
|
|
|
|
// 编辑字幕
|
|
|
- lazy var subtitleEditView : BFSubtitleEditView = {
|
|
|
+ lazy var subtitleEditView: BFSubtitleEditView = {
|
|
|
let subtitleEditView = BFSubtitleEditView(frame: CGRect(x: 0, y: 0, width: cScreenWidth, height: cScreenHeigth))
|
|
|
subtitleEditView.isHidden = true
|
|
|
|
|
@@ -317,7 +320,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}()
|
|
|
|
|
|
// 显示字幕
|
|
|
- lazy var subtitleLabel : PQSubTitleLabel = {
|
|
|
+ lazy var subtitleLabel: PQSubTitleLabel = {
|
|
|
let subtitleLabel = PQSubTitleLabel()
|
|
|
subtitleLabel.textAlignment = .center
|
|
|
subtitleLabel.numberOfLines = 0
|
|
@@ -329,12 +332,12 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}()
|
|
|
|
|
|
// 音量设置
|
|
|
- lazy var audioSettingView : BFAudioSettingView = {
|
|
|
+ lazy var audioSettingView: BFAudioSettingView = {
|
|
|
let audioSettingView = BFAudioSettingView(frame: CGRect(x: 0, y: 0, width: cScreenWidth, height: cScreenHeigth))
|
|
|
audioSettingView.isHidden = true
|
|
|
audioSettingView.haveSpeakSlider.valueIsInt = true
|
|
|
audioSettingView.noSpeakSlider.valueIsInt = true
|
|
|
- audioSettingView.callBack = {[weak self] haveSpeak, noHaveSpeak in
|
|
|
+ audioSettingView.callBack = { [weak self] haveSpeak, noHaveSpeak in
|
|
|
BFLog(1, message: "haveSpeak is:\(haveSpeak),noHaveSpeak is:\(noHaveSpeak)")
|
|
|
self?.haveSpeakVolume = haveSpeak / 100.0
|
|
|
self?.noSpeakVolume = noHaveSpeak / 100.0
|
|
@@ -344,9 +347,9 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}()
|
|
|
|
|
|
// 录音识别文字
|
|
|
- var speechTranscriberUtil : PQSpeechTranscriberUtil?
|
|
|
+ var speechTranscriberUtil: PQSpeechTranscriberUtil?
|
|
|
|
|
|
- lazy var progressThumV : BFVideoThumbProgressView = {
|
|
|
+ lazy var progressThumV: BFVideoThumbProgressView = {
|
|
|
let vv = BFVideoThumbProgressView(frame: CGRect(x: 0, y: 54, width: cScreenWidth, height: 50))
|
|
|
vv.dragStartHandle = { [weak self] in
|
|
|
self?.isDragingProgressSlder = true
|
|
@@ -362,7 +365,6 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
if !sself.isDragingProgressSlder {
|
|
|
BFLog(1, message: "isDragingProgressSlder 进行中")
|
|
|
-
|
|
|
}
|
|
|
sself.isDragingProgressSlder = true
|
|
|
|
|
@@ -383,7 +385,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
return vv
|
|
|
}()
|
|
|
|
|
|
- lazy var collectionView : UICollectionView = {
|
|
|
+ lazy var collectionView: UICollectionView = {
|
|
|
let flowLayout = UICollectionViewFlowLayout()
|
|
|
flowLayout.minimumLineSpacing = 0
|
|
|
flowLayout.minimumInteritemSpacing = 0
|
|
@@ -474,7 +476,6 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
BFLog(message: "新录制完成::::\(materialsModel?.locationPath ?? "")")
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// 字幕设置回调
|
|
|
// 设置默认值
|
|
|
setSubtitleStyle(settingModel: subtitleSettingView.subtitle.setting)
|
|
@@ -753,23 +754,24 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
// 停止进度条滚动
|
|
|
if isDragingProgressSlder {
|
|
|
- return
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
pause()
|
|
|
isRecording = true
|
|
|
|
|
|
let model = PQVoiceModel()
|
|
|
- model.startTime = currentAssetProgress.seconds
|
|
|
+ // 开始时间
|
|
|
+ model.startTime = itemModels[currItemModelIndex].mediaType == .IMAGE ? itemModels[currItemModelIndex].materialDuraion : currentAssetProgress.seconds
|
|
|
model.volume = 100
|
|
|
recorderManager.voiceModel = model
|
|
|
recorderManager.startRecord(index: 1)
|
|
|
if recordStartTime <= 0 {
|
|
|
- recordStartTime = currentAssetProgress.seconds
|
|
|
+ recordStartTime = itemModels[currItemModelIndex].mediaType == .IMAGE ? itemModels[currItemModelIndex].materialDuraion : currentAssetProgress.seconds
|
|
|
}
|
|
|
// 添加撤销记录点
|
|
|
events.append(WithDrawModel(type: 2, timestamp: model.startTime))
|
|
|
-
|
|
|
+
|
|
|
// DispatchQueue.main.async {[weak self] in
|
|
|
// let model = PQVoiceModel()
|
|
|
// model.startTime = self?.currentAssetProgress.seconds ?? 0
|
|
@@ -783,7 +785,6 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
// self?.events.append(WithDrawModel(type: 2, timestamp: model.startTime))
|
|
|
//
|
|
|
// }
|
|
|
-
|
|
|
|
|
|
isRecording = true
|
|
|
|
|
@@ -798,20 +799,19 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
sself.speechTranscriberUtil?.delegate = sself
|
|
|
sself.speechTranscriberUtil?.startTranscriber()
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if itemModels[currItemModelIndex].mediaType == .VIDEO {
|
|
|
-
|
|
|
if !movieIsProcessing {
|
|
|
movie?.startProcessing()
|
|
|
movieIsProcessing = true
|
|
|
}
|
|
|
assetPlayer?.volume = 0
|
|
|
assetPlayer?.play()
|
|
|
-
|
|
|
+
|
|
|
// 暂停状态
|
|
|
(collectionView.cellForItem(at: IndexPath(item: currItemModelIndex, section: 0)) as? BFImageCoverViewCell)?.playBtn.isSelected = true
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
recorderManager.audioRecorder?.recorderProgross = { [weak self] progress in
|
|
|
BFLog(1, message: "curr:录音进度--\(progress)")
|
|
|
if self?.indirectionView == nil {
|
|
@@ -822,11 +822,11 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
// 注:视频无法以录制进度驱动,因当录音开始录音时播放器还未播放,导致进度不一致
|
|
|
// 注:在录制停止时,视频播放器进度依然在走,误差在80毫秒左右
|
|
|
if self?.isRecording ?? false {
|
|
|
- let ratioX = 0.08
|
|
|
- self?.indirectionView?.setProgress(start: self?.recordStartTime ?? 0, progress: progress - ratioX)
|
|
|
- }
|
|
|
- if self?.itemModels[self?.currItemModelIndex ?? 0].mediaType == .IMAGE {
|
|
|
- self?.imageRecordProgress(isRecord: true, progress: progress)
|
|
|
+ let progress = self?.itemModels[self?.currItemModelIndex ?? 0].mediaType == .IMAGE ? progress : progress - 0.08
|
|
|
+ self?.indirectionView?.setProgress(start: self?.recordStartTime ?? 0, progress: progress)
|
|
|
+ if self?.itemModels[self?.currItemModelIndex ?? 0].mediaType == .IMAGE {
|
|
|
+ self?.imageRecordProgress(isRecord: true, progress: progress)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -977,18 +977,18 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
if elems.count > 0 {
|
|
|
// TODO: 停在了录音区间,显示删除按钮
|
|
|
- if fabs(elems[0].1.endTime - self.currentAssetProgress.seconds) < 0.5 {
|
|
|
+ if fabs(elems[0].1.endTime - 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
|
|
|
-
|
|
|
+
|
|
|
deleteRecordBtn.isHidden = true
|
|
|
recordBtn.isHidden = false
|
|
|
isStopAtRecordRange = -1
|
|
|
BFLog(1, message: "停在了录音区间外 \(isStopAtRecordRange)")
|
|
|
- }else {
|
|
|
- if fabs(elems[0].1.startTime - self.currentAssetProgress.seconds) < 0.5 {
|
|
|
+ } else {
|
|
|
+ if fabs(elems[0].1.startTime - currentAssetProgress.seconds) < 0.5 {
|
|
|
BFLog(1, message: "吸附在录音开始")
|
|
|
// changeWithDrawBtnLayout(true)
|
|
|
changeProgress(progress: Float(elems[0].1.startTime / itemModels[currItemModelIndex].materialDuraion))
|
|
@@ -997,7 +997,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
deleteRecordBtn.isHidden = false
|
|
|
recordBtn.isHidden = true
|
|
|
isStopAtRecordRange = elems.first!.0
|
|
|
-
|
|
|
+
|
|
|
BFLog(1, message: "停在了录音区间里 \(isStopAtRecordRange)")
|
|
|
}
|
|
|
} else {
|
|
@@ -1139,7 +1139,6 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
}
|
|
|
BFLog(1, message: "应当播放:\(shouldPlayRecordIndex), 当前播放:\(currentPlayRecordIndex)")
|
|
|
-
|
|
|
}
|
|
|
|
|
|
func play() {
|
|
@@ -1151,7 +1150,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
try? AVAudioSession.sharedInstance().setCategory(.playAndRecord, options: .defaultToSpeaker)
|
|
|
try AVAudioSession.sharedInstance().setActive(true)
|
|
|
} catch {}
|
|
|
-
|
|
|
+
|
|
|
BFLog(1, message: "开启session \(Date().timeIntervalSince(a))")
|
|
|
}
|
|
|
isNormalPlaying = true
|
|
@@ -1166,7 +1165,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
currentAssetProgress = CMTime.zero
|
|
|
}
|
|
|
if itemModels[currItemModelIndex].mediaType == .VIDEO {
|
|
|
- assetPlayer?.volume = self.noSpeakVolume
|
|
|
+ assetPlayer?.volume = noSpeakVolume
|
|
|
if !movieIsProcessing {
|
|
|
movie?.startProcessing()
|
|
|
movieIsProcessing = true
|
|
@@ -1184,7 +1183,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
// movie?.cancelProcessing()
|
|
|
assetPlayer?.pause()
|
|
|
recordPlayer?.pause()
|
|
|
-
|
|
|
+
|
|
|
pauseTime = currentAssetProgress.seconds
|
|
|
|
|
|
assetPlayer?.seek(to: currentAssetProgress, toleranceBefore: CMTime(value: 1, timescale: 1_000_000), toleranceAfter: CMTime(value: 1, timescale: 1_000_000), completionHandler: { _ in
|
|
@@ -1194,7 +1193,6 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
|
|
|
func fetchVideo() {
|
|
|
-
|
|
|
if assets.count > 0 {
|
|
|
currItemModelIndex = 0
|
|
|
for (index, asset) in assets.enumerated() {
|
|
@@ -1204,7 +1202,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
itemModels.append(itemModel)
|
|
|
if index == 0 {
|
|
|
if asset.mediaType == .video {
|
|
|
- itemModel.fetchAVUrlAsset = { [weak self, weak itemModel] uralss in
|
|
|
+ itemModel.fetchAVUrlAsset = { [weak self, weak itemModel] _ in
|
|
|
// self?.export(avsss:uralss)
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
self?.progressThumV.recordItem = itemModel
|
|
@@ -1307,7 +1305,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
BFLog(1, message: "curr:\(CMTimeGetSeconds(currentAssetProgress))")
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
self?.progreddL.text = String(format: "%@", CMTimeGetSeconds(time).formatDurationToHMS())
|
|
|
- let su = !(self?.isDragingProgressSlder ?? false) || (self?.isRecording ?? false ) || (self?.isNormalPlaying ?? false)
|
|
|
+ let su = !(self?.isDragingProgressSlder ?? false) || (self?.isRecording ?? false) || (self?.isNormalPlaying ?? false)
|
|
|
if su {
|
|
|
self?.progressThumV.progress = time.seconds
|
|
|
}
|
|
@@ -1332,20 +1330,19 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
|
|
|
// MARK: - 录音对应图像绘制
|
|
|
-
|
|
|
+
|
|
|
// 撤销按钮修改title,重绘
|
|
|
- func changeWithDrawBtnLayout(_ recorded:Bool) {
|
|
|
+ func changeWithDrawBtnLayout(_ recorded: Bool) {
|
|
|
if recorded {
|
|
|
withDrawBtn.setTitle("撤销录制", for: .normal)
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
withDrawBtn.setTitle("回退", for: .normal)
|
|
|
}
|
|
|
withDrawBtn.imageEdgeInsets = UIEdgeInsets(top: -withDrawBtn.imageView!.height, left: 0, bottom: 0, right: -withDrawBtn.titleLabel!.width)
|
|
|
withDrawBtn.titleEdgeInsets = UIEdgeInsets(top: withDrawBtn.titleLabel!.height + 2, left: -withDrawBtn.imageView!.width, bottom: 0, right: 0)
|
|
|
-
|
|
|
+
|
|
|
withDrawBtn.setNeedsLayout()
|
|
|
withDrawBtn.layoutIfNeeded()
|
|
|
-
|
|
|
}
|
|
|
|
|
|
// 通过缩略图进度条控制播放进度
|
|
@@ -1403,10 +1400,10 @@ extension BFRecordScreenController: PQSpeechTranscriberUtilDelegate {
|
|
|
// 1,保存字幕数据 begin_time是开始出现文字的时间,time 是结束文字出现的时间 单位都为毫秒,都是相对于录制音频数据整段时间。self.recorderManager.voiceModel?.startTime 为开始的录制的时间,开始和结束都要加上这个时差
|
|
|
|
|
|
let newSubtitle = PQEditSubTitleModel()
|
|
|
-
|
|
|
- //这里加300ms 是因为返回结果为了切到字,时长提前一些时间,具体时间官方没说和原音频有关系。这里我们先延后300ms 单位:毫秒。
|
|
|
+
|
|
|
+ // 这里加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
|
|
|
var showText = ((payload?["result"]) as? String) ?? ""
|
|
|
if showText.count > subtitleMaxlength {
|
|
@@ -1421,24 +1418,22 @@ extension BFRecordScreenController: PQSpeechTranscriberUtilDelegate {
|
|
|
self.itemModels[self.currItemModelIndex].titleStickers.append(newSubtitle)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- func reloadMaterial(recordItem : BFRecordItemModel) {
|
|
|
-
|
|
|
+
|
|
|
+ func reloadMaterial(recordItem: BFRecordItemModel) {
|
|
|
if let path = recordItem.localPath, let lastCell: BFImageCoverViewCell = collectionView.cellForItem(at: IndexPath(item: currItemModelIndex, section: 0)) as? BFImageCoverViewCell {
|
|
|
-
|
|
|
setVideoPlay(item: recordItem.playItem, imageView: lastCell.playView)
|
|
|
setAudioPlay(item: recordItem.playItem)
|
|
|
-
|
|
|
+
|
|
|
let degress = degressFromVideoFile(url: URL(fileURLWithPath: path))
|
|
|
- switch (degress) {
|
|
|
+ switch degress {
|
|
|
case 90:
|
|
|
- lastCell.playView.setInputRotation(GPUImageRotationMode.init(rawValue: 2), at: 0)
|
|
|
+ lastCell.playView.setInputRotation(GPUImageRotationMode(rawValue: 2), at: 0)
|
|
|
case 180:
|
|
|
- lastCell.playView.setInputRotation(GPUImageRotationMode.init(rawValue: 7), at: 0)
|
|
|
+ lastCell.playView.setInputRotation(GPUImageRotationMode(rawValue: 7), at: 0)
|
|
|
case 270:
|
|
|
- lastCell.playView.setInputRotation(GPUImageRotationMode.init(rawValue: 1), at: 0)
|
|
|
+ lastCell.playView.setInputRotation(GPUImageRotationMode(rawValue: 1), at: 0)
|
|
|
default:
|
|
|
- break;
|
|
|
+ break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1492,7 +1487,7 @@ extension BFRecordScreenController: UICollectionViewDelegate, UICollectionViewDa
|
|
|
// 暂停状态
|
|
|
let lastCell: BFImageCoverViewCell? = collectionView.cellForItem(at: IndexPath(item: currItemModelIndex, section: 0)) as? BFImageCoverViewCell
|
|
|
lastCell?.playBtn.isSelected = false
|
|
|
-
|
|
|
+
|
|
|
let recordItem = itemModels[page]
|
|
|
// 重绘录音区域
|
|
|
indirectionView?.resetAllSubViews(items: recordItem.voiceStickers, percenWidth: recordItem.mediaType == .IMAGE ? progressThumV.thumbImageWidth / 2.0 : 0, totalDuration: recordItem.materialDuraion)
|
|
@@ -1505,8 +1500,7 @@ extension BFRecordScreenController: UICollectionViewDelegate, UICollectionViewDa
|
|
|
assetPlayer?.seek(to: CMTime.zero)
|
|
|
recordPlayer?.seek(to: CMTime.zero)
|
|
|
if recordItem.mediaType == .VIDEO {
|
|
|
- self.reloadMaterial(recordItem: recordItem)
|
|
|
-
|
|
|
+ reloadMaterial(recordItem: recordItem)
|
|
|
assetPlayer?.seek(to: .zero, toleranceBefore: CMTime(value: 1, timescale: 1_000_000), toleranceAfter: CMTime(value: 1, timescale: 1_000_000))
|
|
|
}
|
|
|
if changeItemHandle != nil {
|
|
@@ -1515,7 +1509,7 @@ extension BFRecordScreenController: UICollectionViewDelegate, UICollectionViewDa
|
|
|
// 重设撤销栈
|
|
|
itemModels[currItemModelIndex].events = events
|
|
|
events = itemModels[page].events
|
|
|
- if let cell = collectionView.visibleCells.first as? BFImageCoverViewCell{
|
|
|
+ if let cell = collectionView.visibleCells.first as? BFImageCoverViewCell {
|
|
|
playBtn = cell.playBtn
|
|
|
}
|
|
|
// 更新当前page
|
|
@@ -1543,17 +1537,17 @@ public extension BFRecordScreenController {
|
|
|
return
|
|
|
}
|
|
|
isNormalPlaying = true
|
|
|
- playRecord(at: currentAssetProgress, periodicTimeObserver: { [weak self] currentT, currentItem in
|
|
|
- BFLog(message: "播放一段进度:\(currentT),\(currentItem)")
|
|
|
- self?.imageRecordProgress(progress: CMTimeGetSeconds(currentT) / 2)
|
|
|
- // 更新字幕
|
|
|
- self?.updateSubtitle(time: currentT)
|
|
|
+ BFLog(message: "开始播放第\(currImagePlayIndex)段:\(itemModels[currItemModelIndex].voiceStickers[currImagePlayIndex].startTime)")
|
|
|
+ playRecord(at: CMTime(seconds: itemModels[currItemModelIndex].voiceStickers[currImagePlayIndex].startTime, preferredTimescale: 1000), periodicTimeObserver: { [weak self] currentT, currentItem in
|
|
|
+ BFLog(message: "播放第\(self?.currImagePlayIndex ?? 0)段进度:\(currentT),\(currentItem)")
|
|
|
+ self?.imageRecordProgress(progress: CMTimeGetSeconds(currentT))
|
|
|
}, didPlayToEndTime: { [weak self] recordedAudio, currentItem in
|
|
|
- BFLog(message: "播放一段结束:\(String(describing: recordedAudio)),\(String(describing: currentItem))")
|
|
|
+ BFLog(message: "播放第\(self?.currImagePlayIndex ?? 0)段结束:\(String(describing: recordedAudio)),\(String(describing: currentItem))")
|
|
|
if (recordedAudio?.endTime ?? 0) >= (self?.itemModels[self?.currItemModelIndex ?? 0].voiceStickers.last?.endTime ?? 0) {
|
|
|
self?.isEndPlay = true
|
|
|
self?.pause()
|
|
|
} else {
|
|
|
+ self?.currImagePlayIndex += 1
|
|
|
self?.imageRecordPlay()
|
|
|
}
|
|
|
}) { [weak self] _, _ in
|
|
@@ -1566,12 +1560,12 @@ public extension BFRecordScreenController {
|
|
|
|
|
|
/// 处理图片素材录音
|
|
|
func imageRecordProgress(isRecord: Bool = false, progress: Float64) {
|
|
|
- BFLog(message: "图片录音进度:\(progress)")
|
|
|
if isRecord {
|
|
|
currentAssetProgress = CMTime(seconds: itemModels[currItemModelIndex].materialDuraion + progress, preferredTimescale: 1000)
|
|
|
} else {
|
|
|
currentAssetProgress = CMTime(seconds: progress, preferredTimescale: 1000)
|
|
|
}
|
|
|
+ BFLog(message: "图片录音进度:\(progress),currentAssetProgress=\(currentAssetProgress)")
|
|
|
if itemModels[currItemModelIndex].mediaType == .IMAGE {
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
self?.progreddL.text = String(format: "%@", ((self?.currentAssetProgress.seconds ?? 0) + (isRecord ? 0 : progress)).formatDurationToHMS())
|