|
@@ -54,7 +54,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
var movie :GPUImageMovie?
|
|
|
var playView :GPUImageView?
|
|
|
var isDragingProgressSlder : Bool = false
|
|
|
-
|
|
|
+ var isStopAtRecordRange = -1
|
|
|
|
|
|
let recordSettings:[String : Any] = [AVSampleRateKey : 44100.0,
|
|
|
AVFormatIDKey : kAudioFormatLinearPCM,
|
|
@@ -137,7 +137,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
lazy var recordBtn:UIButton = {
|
|
|
let btn = UIButton(type: .custom)
|
|
|
- btn.backgroundColor = ThemeStyleGreen()
|
|
|
+ btn.backgroundColor = ThemeStyleColor
|
|
|
btn.setTitle("按住 说话", for: .normal)
|
|
|
btn.adjustsImageWhenHighlighted = false
|
|
|
btn.addTarget(self, action: #selector(startRecord), for: .touchDown)
|
|
@@ -172,7 +172,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
btn.setImage(imageInRecordScreenKit(by: "changeVoice_h"), for: .highlighted)
|
|
|
btn.setTitle("变声", for: .normal)
|
|
|
btn.setTitleColor(.white, for: .normal)
|
|
|
- btn.setTitleColor(ThemeStyleGreen(), for: .highlighted)
|
|
|
+ btn.setTitleColor(ThemeStyleColor, for: .highlighted)
|
|
|
btn.titleLabel?.font = UIFont.systemFont(ofSize: 12)
|
|
|
btn.contentVerticalAlignment = UIControl.ContentVerticalAlignment.center;
|
|
|
btn.addTarget(self, action: #selector(changeVoiceAction), for: .touchUpInside)
|
|
@@ -204,8 +204,8 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
if sself.isNormalPlaying || sself.isRecording {
|
|
|
sself.pause()
|
|
|
- sself.isDragingProgressSlder = true
|
|
|
}
|
|
|
+ sself.isDragingProgressSlder = true
|
|
|
sself.changeProgress(progress: process)
|
|
|
}
|
|
|
}
|
|
@@ -214,11 +214,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
guard let sself = self else {
|
|
|
return
|
|
|
}
|
|
|
- sself.changeProgress(progress: process)
|
|
|
-
|
|
|
- sself.isDragingProgressSlder = false
|
|
|
- sself.currentPlayRecordIndex = -1
|
|
|
- sself.hadPrepareToPlayRecord = false
|
|
|
+ sself.thumbViewEnded(progress: process)
|
|
|
}
|
|
|
vv.isHidden = true
|
|
|
return vv
|
|
@@ -421,12 +417,18 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
|
|
|
@objc func playVideo(btn:UIButton){
|
|
|
- btn.isSelected ? pause() : play()
|
|
|
+ if btn.isSelected {
|
|
|
+ pause()
|
|
|
+ searchStopAtRecordRange()
|
|
|
+ }else {
|
|
|
+ play()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@objc func sliderTouchBegan(sender _: UISlider) {
|
|
|
isDragingProgressSlder = true
|
|
|
pause()
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@objc func sliderTouchEnded(sender: UISlider) {
|
|
@@ -437,7 +439,30 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
}
|
|
|
@objc func sliderValueDidChanged(sender: UISlider) {
|
|
|
changeProgress(progress: sender.value)
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
+ func thumbViewEnded(progress:Float) {
|
|
|
+ changeProgress(progress: progress)
|
|
|
+ isDragingProgressSlder = false
|
|
|
+ currentPlayRecordIndex = -1
|
|
|
+ hadPrepareToPlayRecord = false
|
|
|
+
|
|
|
+ searchStopAtRecordRange()
|
|
|
+ }
|
|
|
+
|
|
|
+ func searchStopAtRecordRange() {
|
|
|
+
|
|
|
+ let elems = itemModels[currItemModelIndex].voiceStickers.enumerated().filter({ elem in
|
|
|
+ elem.1.startTime <= self.currentAssetProgress.seconds && elem.1.endTime > self.currentAssetProgress.seconds
|
|
|
+ })
|
|
|
+ if elems.count > 0{
|
|
|
+
|
|
|
+ isStopAtRecordRange = elems.first!.0
|
|
|
+ BFLog(1, message: "停在了录音区间 里")
|
|
|
+ }else {
|
|
|
+ isStopAtRecordRange = -1
|
|
|
+ BFLog(1, message: "停在了录音区间 外")
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -535,7 +560,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
if currentPlayRecordIndex == -1 && self.isNormalPlaying{
|
|
|
let second = CMTimeGetSeconds(currentT) - recordedAudio.startTime
|
|
|
DispatchQueue.main.async {[weak self] in
|
|
|
- self?.recordPlayer?.seek(to: CMTime(value: CMTimeValue(second), timescale: 100), toleranceBefore: CMTime(value: 1, timescale: 1000), toleranceAfter: CMTime(value: 1, timescale: 1000), completionHandler: {[weak self] finished in
|
|
|
+ self?.recordPlayer?.seek(to: CMTime(value: CMTimeValue(second), timescale: 100), toleranceBefore: CMTime(value: 1, timescale: 1000000), toleranceAfter: CMTime(value: 1, timescale: 1000000), completionHandler: {[weak self] finished in
|
|
|
if finished && (self?.isNormalPlaying ?? false) {
|
|
|
self?.recordPlayer?.play()
|
|
|
BFLog(1, message: "录音开始播放 playing, \(second), \(CMTimeGetSeconds(self?.recordPlayer?.currentItem?.duration ?? .zero))")
|
|
@@ -584,7 +609,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
assetPlayer?.pause()
|
|
|
recordPlayer?.pause()
|
|
|
|
|
|
- assetPlayer?.seek(to: self.currentAssetProgress , toleranceBefore: CMTime(value: 1, timescale: 1000), toleranceAfter: CMTime(value: 1, timescale: 1000), completionHandler: { finished in
|
|
|
+ assetPlayer?.seek(to: self.currentAssetProgress , toleranceBefore: CMTime(value: 1, timescale: 1000000), toleranceAfter: CMTime(value: 1, timescale: 1000000), completionHandler: { finished in
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -596,6 +621,9 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
for (index, asset) in self.assets.enumerated() {
|
|
|
let itemModel = BFRecordItemModel()
|
|
|
itemModel.index = 0
|
|
|
+ itemModel.width = asset.pixelWidth
|
|
|
+ itemModel.height = asset.pixelHeight
|
|
|
+
|
|
|
itemModels.append(itemModel)
|
|
|
|
|
|
let options = PHVideoRequestOptions()
|
|
@@ -672,21 +700,24 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
assetPlayer = AVPlayer(playerItem: item)
|
|
|
avplayerTimeObserver = assetPlayer?.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 100), queue: DispatchQueue.global()) {[weak self] time in
|
|
|
|
|
|
- if !((self?.isNormalPlaying ?? false) || (self?.isRecording ?? false)) {
|
|
|
- return
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
- self?.playRecord(at: time)
|
|
|
-
|
|
|
self?.currentAssetProgress = time
|
|
|
BFLog(1, message: "curr:\(CMTimeGetSeconds(time))")
|
|
|
- if CMTimeGetSeconds(item.duration) > 0, !(self?.isDragingProgressSlder ?? false) {
|
|
|
+ if CMTimeGetSeconds(item.duration) > 0 {
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
self?.progreddL.text = String(format: "%.2f", CMTimeGetSeconds(time), CMTimeGetSeconds(item.duration))
|
|
|
- self?.progressThumV.progress = time.seconds
|
|
|
+ if !(self?.isDragingProgressSlder ?? false){
|
|
|
+ self?.progressThumV.progress = time.seconds
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if (self?.isNormalPlaying ?? false) || (self?.isRecording ?? false) {
|
|
|
+
|
|
|
+ self?.playRecord(at: time)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
} as? NSKeyValueObservation
|
|
|
}
|
|
|
|
|
@@ -695,6 +726,8 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
BFLog(1, message: "AVPlayerItemDidPlayToEndTime = \(notify)")
|
|
|
self?.isNormalPlaying = false
|
|
|
self?.assetPlayer?.seek(to: CMTime.zero)
|
|
|
+ self?.progressThumV.progress = 0
|
|
|
+
|
|
|
self?.currentPlayRecordIndex = -1
|
|
|
if self?.isRecording ?? false {
|
|
|
self?.endRecord()
|
|
@@ -716,24 +749,6 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
|
|
|
}
|
|
|
|
|
|
- func generationTimeRanges() -> [CMTimeRange]{
|
|
|
-
|
|
|
- var ranges = [CMTimeRange]()
|
|
|
- var start : Double = 0
|
|
|
- for model in itemModels[currItemModelIndex].voiceStickers {
|
|
|
- if model.startTime > start{
|
|
|
- let range = CMTimeRange(start: CMTime(seconds: start, preferredTimescale: 100), duration: CMTime(seconds: model.startTime - start, preferredTimescale: 100))
|
|
|
- ranges.append(range)
|
|
|
-
|
|
|
- }
|
|
|
- ranges.append(CMTimeRange(start: CMTime(seconds: model.startTime, preferredTimescale: 100), end: CMTime(seconds: model.endTime, preferredTimescale: 100)))
|
|
|
- start = model.endTime
|
|
|
- }
|
|
|
-
|
|
|
- return ranges
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
|
|
|
|
|
|
func changeProgress(progress:Float) {
|
|
@@ -743,7 +758,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
self!.progreddL.text = String(format: "%.2f", CMTimeGetSeconds(self!.currentAssetProgress))
|
|
|
}
|
|
|
|
|
|
- assetPlayer!.seek(to: self.currentAssetProgress, toleranceBefore: CMTime(value: 1, timescale: 1000), toleranceAfter: CMTime(value: 1, timescale: 1000)) { finished in
|
|
|
+ assetPlayer!.seek(to: self.currentAssetProgress, toleranceBefore: CMTime(value: 1, timescale: 1000000), toleranceAfter: CMTime(value: 1, timescale: 1000000)) { finished in
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -763,7 +778,7 @@ public class BFRecordScreenController: BFBaseViewController {
|
|
|
let height = sself.progressThumV.progessIndicateBackV.height
|
|
|
sself.itemModels[sself.currItemModelIndex].voiceStickers.forEach { model in
|
|
|
let lineV = UIView(frame: CGRect(x: model.startTime * width / totalDur , y: 0, width: (model.endTime - model.startTime) * width / totalDur, height: height))
|
|
|
- lineV.backgroundColor = ThemeStyleGreen()
|
|
|
+ lineV.backgroundColor = ThemeStyleColor
|
|
|
sself.progressThumV.progessIndicateBackV.addSubview(lineV)
|
|
|
}
|
|
|
}
|