소스 검색

1.图片录音播放

wenweiwei 3 년 전
부모
커밋
d4b94a853d
1개의 변경된 파일33개의 추가작업 그리고 35개의 파일을 삭제
  1. 33 35
      BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

+ 33 - 35
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -175,8 +175,8 @@ public class BFRecordScreenController: BFBaseViewController {
 
     lazy var deleteRecordBtn: UIButton = {
         let btn = UIButton(type: .custom)
-       
-        btn.backgroundColor =  UIColor.hexColor(hexadecimal: "#FF0000", alpha: 0.3)
+
+        btn.backgroundColor = UIColor.hexColor(hexadecimal: "#FF0000", alpha: 0.3)
         btn.setTitle("删除录制", for: .normal)
         btn.adjustsImageWhenHighlighted = false
         btn.titleLabel?.font = UIFont.boldSystemFont(ofSize: 18)
@@ -305,8 +305,8 @@ public class BFRecordScreenController: BFBaseViewController {
             BFLog(1, message: "haveSpeak is:\(haveSpeak),noHaveSpeak is:\(noHaveSpeak)")
             self?.haveSpeakVolume = haveSpeak / 100.0
             self?.noSpeakVolume = noHaveSpeak / 100.0
-            if !(self?.isNormalPlaying ?? false) && !(self?.isRecording ?? false) {
-                if (self?.deleteRecordBtn.isHidden ?? false)  {
+            if !(self?.isNormalPlaying ?? false), !(self?.isRecording ?? false) {
+                if self?.deleteRecordBtn.isHidden ?? false {
                     self?.recordPlayer?.volume = 0
                     self?.assetPlayer?.volume = self?.noSpeakVolume ?? 1.0
                 } else {
@@ -490,10 +490,9 @@ public class BFRecordScreenController: BFBaseViewController {
                     if let voice = self?.itemModels[self?.currItemModelIndex ?? 0].voiceStickers.first(where: { m in
                         m.wavFilePath == audioFilePath
                     }) {
-                        newSubtitle.timelineIn = voice.startCMTime + CMTime(seconds:  Float64((((payload?["begin_time"]) as? Int) ?? 0) + 300) / 1000.0, preferredTimescale: 1000)
-                        newSubtitle.timelineOut = voice.startCMTime +  CMTime(seconds: Float64(((payload?["time"]) as? Int) ?? 0) / 1000.0, preferredTimescale: 1000)
+                        newSubtitle.timelineIn = voice.startCMTime + CMTime(seconds: Float64((((payload?["begin_time"]) as? Int) ?? 0) + 300) / 1000.0, preferredTimescale: 1000)
+                        newSubtitle.timelineOut = voice.startCMTime + CMTime(seconds: Float64(((payload?["time"]) as? Int) ?? 0) / 1000.0, preferredTimescale: 1000)
 
-                        
                         if (newSubtitle.timelineIn - voice.endCMTime).seconds > 0.1 {
                             BFLog(1, message: "卡在录音尾巴上了1")
                             newSubtitle.timelineIn = newSubtitle.timelineIn - CMTime(seconds: 0.1, preferredTimescale: 1000)
@@ -509,7 +508,7 @@ public class BFRecordScreenController: BFBaseViewController {
                 newSubtitle.audioFilePath = audioFilePath ?? ""
 
                 BFLog(message: "添加字幕数据 timelineIn \(newSubtitle.timelineIn) timelineOut \(newSubtitle.timelineOut) text: \(newSubtitle.text) 音频路径为:\(audioFilePath ?? "") 传入的地址:\(self?.recorderManager?.voiceModel?.wavFilePath ?? "aa")")
-                
+
                 newSubtitle.setting = self?.subtitleSettingView.subtitle.setting ?? BFSubTitileSettingModel()
 
                 self?.itemModels[self?.currItemModelIndex ?? 0].titleStickers.append(newSubtitle)
@@ -651,7 +650,6 @@ public class BFRecordScreenController: BFBaseViewController {
             BFLog(message: "新录制完成::::\(materialsModel?.locationPath ?? "")")
         }
 
-      
         // 设置默认值
         setSubtitleStyle(settingModel: subtitleSettingView.subtitle.setting)
         // 字幕设置回调
@@ -706,12 +704,12 @@ public class BFRecordScreenController: BFBaseViewController {
     /// - Parameter time: 当前播放的进度
     func updateSubtitle(time: CMTime) {
         BFLog(message: "currTime is \(CMTimeGetSeconds(time))")
-        if isRecording ||  !subtitleSettingView.subtitle.setting.subtitleIsShow{
+        if isRecording || !subtitleSettingView.subtitle.setting.subtitleIsShow {
             return
         }
         var findShowSubtitle: PQEditSubTitleModel?
         for (index, subtitle) in itemModels[currItemModelIndex].titleStickers.enumerated() {
-            if CMTimeCompare(subtitle.timelineIn, time) <= 0 , CMTimeCompare(subtitle.timelineOut, time) >= 0  {
+            if CMTimeCompare(subtitle.timelineIn, time) <= 0, CMTimeCompare(subtitle.timelineOut, time) >= 0 {
                 findShowSubtitle = subtitle
                 BFLog(1, message: "找到要显示的字幕 in \((findShowSubtitle?.timelineIn ?? .zero).seconds) out \((findShowSubtitle?.timelineOut ?? .zero).seconds) text:\(findShowSubtitle?.text ?? "") currTime is \(CMTimeGetSeconds(time))")
                 showSubtitleIndex = index
@@ -731,8 +729,7 @@ public class BFRecordScreenController: BFBaseViewController {
     /// 设置字幕样式和位置
     /// - Parameter settingModel: 样式model
     func setSubtitleStyle(settingModel: BFSubTitileSettingModel) {
-       
-        subtitleBtn.setImage(imageInRecordScreenKit(by:  settingModel.subtitleIsShow ? "subtitleBtn_on" : "subtitleBtn_off"), for: .normal)
+        subtitleBtn.setImage(imageInRecordScreenKit(by: settingModel.subtitleIsShow ? "subtitleBtn_on" : "subtitleBtn_off"), for: .normal)
         if settingModel.subtitleIsShow {
             // 设置样式
             subtitleLabel.strokeColor = settingModel.strokeColor
@@ -753,7 +750,7 @@ public class BFRecordScreenController: BFBaseViewController {
             } else { // 上
                 subtitleLabel.frame = CGRect(x: leftPoint, y: cScreenHeigth * 0.12, width: cScreenWidth - 37 * 2, height: height)
             }
-        }else{
+        } else {
             subtitleLabel.text = ""
         }
     }
@@ -814,7 +811,7 @@ public class BFRecordScreenController: BFBaseViewController {
             make.width.equalTo(40)
             make.height.equalTo(62)
         }
-        
+
         subtitleBtn.snp.makeConstraints { make in
             make.right.equalTo(soundSettingBtn)
             make.top.equalTo(soundSettingBtn.snp.bottom).offset(18)
@@ -856,10 +853,7 @@ public class BFRecordScreenController: BFBaseViewController {
                 let nowPoint = recognizer.location(in: bottomeView)
                 BFLog(1, message: "nowPoint x: \(nowPoint.x) y:\(nowPoint.y)")
                 if recordBtn.frame.contains(nowPoint) {
-                
-                } else {
-                    
-                }
+                } else {}
             }
 
         case .ended:
@@ -979,8 +973,6 @@ public class BFRecordScreenController: BFBaseViewController {
         if isDragingProgressSlder {
             return
         }
- 
-        
 
 //        progressThumV.progressView.isUserInteractionEnabled = false
 //        collectionView.isScrollEnabled = false
@@ -993,8 +985,7 @@ public class BFRecordScreenController: BFBaseViewController {
             BFLog(message: "录音机初始化错误!!!")
             return
         }
-        
-        
+
         // 开始时间
         beginOnStartBtn = true
         isRecording = true
@@ -1076,7 +1067,7 @@ public class BFRecordScreenController: BFBaseViewController {
     /// 不足一秒,主动取消录制
     /// - Parameter voiceModel: <#voiceModel description#>
     @objc func recordManagerCancelRecord(voiceModel: PQVoiceModel?) {
-        if voiceModel != nil && (currentAssetProgress.seconds - (recorderManager?.voiceModel?.startCMTime.seconds ?? 0) < 1.0) {
+        if voiceModel != nil, currentAssetProgress.seconds - (recorderManager?.voiceModel?.startCMTime.seconds ?? 0) < 1.0 {
             cShowHUB(superView: nil, msg: "最短录制1秒")
         }
         // 删除文件
@@ -1510,15 +1501,22 @@ public class BFRecordScreenController: BFBaseViewController {
                 // 两个逻辑:如果在播,则跳过;如果暂停拖动到中间,则seek
                 if sself.isNormalPlaying {
                     let second = CMTimeGetSeconds(currentT) - recordedAudio.startCMTime.seconds
-                    DispatchQueue.main.async { [weak sself] in
-                        self?.recordPlayer?.seek(to: CMTime(value: CMTimeValue(second * 1_000_000), timescale: 1_000_000), toleranceBefore: CMTime(value: 1, timescale: 1_000_000), toleranceAfter: CMTime(value: 1, timescale: 1_000_000), completionHandler: { [weak self] finished in
-                            if finished, self?.isNormalPlaying ?? false {
-                                self?.recordPlayer?.play()
-                                self?.recordPlayer?.volume = 1
-                                self?.assetPlayer?.volume = self?.haveSpeakVolume ?? 0
-                                BFLog(1, message: "录音开始播放 playing, \(second), \(CMTimeGetSeconds(self?.recordPlayer?.currentItem?.duration ?? .zero)), \(self?.recordPlayer?.currentItem?.currentTime().seconds ?? 0)")
-                            }
-                        })
+//                    DispatchQueue.main.async { [weak sself] in
+//                        self?.recordPlayer?.seek(to: CMTime(value: CMTimeValue(second * 1_000_000), timescale: 1_000_000), toleranceBefore: CMTime(value: 1, timescale: 1_000_000), toleranceAfter: CMTime(value: 1, timescale: 1_000_000), completionHandler: { [weak self] finished in
+//                            if self?.isNormalPlaying ?? false {
+//                                self?.recordPlayer?.play()
+//                                self?.recordPlayer?.volume = 1
+//                                self?.assetPlayer?.volume = self?.haveSpeakVolume ?? 0
+//                                BFLog(1, message: "录音开始播放 playing, \(second), \(CMTimeGetSeconds(self?.recordPlayer?.currentItem?.duration ?? .zero)), \(self?.recordPlayer?.currentItem?.currentTime().seconds ?? 0)")
+//                            }
+//                        })
+//                    }
+                    sself.recordPlayer?.seek(to: CMTime(value: CMTimeValue(second * 1_000_000), timescale: 1_000_000))
+                    if sself.isNormalPlaying {
+                        sself.recordPlayer?.play()
+                        sself.recordPlayer?.volume = 1
+                        sself.assetPlayer?.volume = sself.haveSpeakVolume
+                        BFLog(1, message: "录音开始播放 playing, \(second), \(CMTimeGetSeconds(sself.recordPlayer?.currentItem?.duration ?? .zero)), \(sself.recordPlayer?.currentItem?.currentTime().seconds ?? 0)")
                     }
                     BFLog(3, message: "重置播放index-\(#function) = \(currentPlayRecordIndex)")
                     BFLog(1, message: "录音开始播放2, \(second), \(CMTimeGetSeconds(recordPlayer?.currentItem?.duration ?? .zero)),index = \(currentPlayRecordIndex)")
@@ -1892,7 +1890,7 @@ extension BFRecordScreenController: UICollectionViewDelegate, UICollectionViewDa
                 sself.reloadMaterial()
             }
         }
-        cell.btnClickHandle = { [weak self] sender, _ in
+        cell.btnClickHandle = { [weak self] _, _ in
             guard let sself = self else {
                 return
             }
@@ -1940,7 +1938,7 @@ extension BFRecordScreenController: UICollectionViewDelegate, UICollectionViewDa
             playBtn.isSelected = (recordItem.mediaType == .IMAGE && recordItem.voiceStickers.count <= 0)
             // 重绘录音区域
             progressThumV.recordItem = recordItem
-            DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { [weak self] in
+            DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in
                 /// 重绘录音进度视图
                 self?.resetAllIndirectionView()
                 // 重绘录音进度