|  | @@ -12,6 +12,7 @@ import GPUImage
 | 
	
		
			
				|  |  |  import Photos
 | 
	
		
			
				|  |  |  import BFCommonKit
 | 
	
		
			
				|  |  |  import BFFramework
 | 
	
		
			
				|  |  | +import UIKit
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |      
 | 
	
	
		
			
				|  | @@ -69,7 +70,7 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  BFLog(1, message: "添加录音文件:\(model?.startTime) -- \(model?.endTime)")
 | 
	
		
			
				|  |  |                  self?.recordList.append(model!)
 | 
	
		
			
				|  |  | -                self?.drewRecordProgessLable()
 | 
	
		
			
				|  |  | +                self?.drawOrUpdateRecordProgessLable()
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -120,6 +121,13 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |          return btn
 | 
	
		
			
				|  |  |      }()
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  | +    lazy var progessSildeBackV : UIView = {
 | 
	
		
			
				|  |  | +        let vv = UIView()
 | 
	
		
			
				|  |  | +        vv.backgroundColor = UIColor.hexColor(hexadecimal: "#303030")
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        return vv
 | 
	
		
			
				|  |  | +    }()
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  |      lazy var progessSilde:BFPlayerSlider = {
 | 
	
		
			
				|  |  |          let sliderView = BFPlayerSlider()
 | 
	
		
			
				|  |  |          let tjbV = UIView(frame: CGRect(x: 0, y: 0, width: 4, height: 16))
 | 
	
	
		
			
				|  | @@ -129,8 +137,8 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |          sliderView.setMaximumTrackImage(thbImage, for: .normal)
 | 
	
		
			
				|  |  |          sliderView.setThumbImage(thbImage, for: .highlighted)
 | 
	
		
			
				|  |  |          sliderView.setThumbImage(thbImage, for: .normal)
 | 
	
		
			
				|  |  | -        sliderView.maximumTrackTintColor = UIColor.hexColor(hexadecimal: "#303030")
 | 
	
		
			
				|  |  | -        sliderView.minimumTrackTintColor = UIColor.hexColor(hexadecimal: "#303030")
 | 
	
		
			
				|  |  | +        sliderView.maximumTrackTintColor = .clear // UIColor.hexColor(hexadecimal: "#303030")
 | 
	
		
			
				|  |  | +        sliderView.minimumTrackTintColor = .clear //UIColor.hexColor(hexadecimal: "#303030")
 | 
	
		
			
				|  |  |  //        sliderView.minimumTrackTintColor = UIColor.hexColor(hexadecimal: "#FA6400")
 | 
	
		
			
				|  |  |          sliderView.addTarget(self, action: #selector(sliderTouchBegan(sender:)), for: .touchDown)
 | 
	
		
			
				|  |  |          sliderView.addTarget(self, action: #selector(sliderTouchEnded(sender:)), for: .touchUpInside)
 | 
	
	
		
			
				|  | @@ -200,6 +208,7 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |          view.addSubview(progreddL)
 | 
	
		
			
				|  |  |  //        view.addSubview(toolV)
 | 
	
		
			
				|  |  |          bottomeView.addSubview(recordBtn)
 | 
	
		
			
				|  |  | +        bottomeView.addSubview(progessSildeBackV)
 | 
	
		
			
				|  |  |          bottomeView.addSubview(progessSilde)
 | 
	
		
			
				|  |  |          bottomeView.addSubview(closeBtn)
 | 
	
		
			
				|  |  |          bottomeView.addSubview(nextBtn)
 | 
	
	
		
			
				|  | @@ -233,10 +242,17 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |              make.top.width.height.equalTo(closeBtn)
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  | +        progessSildeBackV.snp.makeConstraints { make in
 | 
	
		
			
				|  |  | +            make.left.equalTo(closeBtn.snp.right).offset(10)
 | 
	
		
			
				|  |  | +            make.right.equalTo(nextBtn.snp.left).offset(-10)
 | 
	
		
			
				|  |  | +            make.centerY.equalTo(closeBtn)
 | 
	
		
			
				|  |  | +            make.height.equalTo(8)
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  |          progessSilde.snp.makeConstraints { make in
 | 
	
		
			
				|  |  |              make.left.equalTo(closeBtn.snp.right).offset(16)
 | 
	
		
			
				|  |  |              make.right.equalTo(nextBtn.snp.left).offset(-16)
 | 
	
		
			
				|  |  | -            make.centerY.equalTo(closeBtn)
 | 
	
		
			
				|  |  | +            make.centerY.equalTo(progessSildeBackV)
 | 
	
		
			
				|  |  |              make.height.equalTo(20)
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          
 | 
	
	
		
			
				|  | @@ -406,23 +422,28 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |              //                self.recordPlayer?.prepareToPlay()
 | 
	
		
			
				|  |  |              currentPlayRecordIndex = -1
 | 
	
		
			
				|  |  |              hadPrepareToPlayRecord = false
 | 
	
		
			
				|  |  | -            BFLog(1, message: "录音播放器初始化")
 | 
	
		
			
				|  |  | +            BFLog(1, message: "录音播放器初始化(有时候不准)")
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  |          synced(currentPlayRecordIndex) {
 | 
	
		
			
				|  |  | -            if CMTimeGetSeconds(currentT) >= recordedAudio.startTime && !hadPrepareToPlayRecord{
 | 
	
		
			
				|  |  | +            if !hadPrepareToPlayRecord
 | 
	
		
			
				|  |  | +                && CMTimeGetSeconds(currentT) >= recordedAudio.startTime
 | 
	
		
			
				|  |  | +                && CMTimeGetSeconds(currentT) <= recordedAudio.endTime - 0.2 // 这个条件是避免录音结束后有小幅度回退导致播放最新录音
 | 
	
		
			
				|  |  | +            {
 | 
	
		
			
				|  |  |                  // 应当开始播放了
 | 
	
		
			
				|  |  |                  // 两个逻辑:如果在播,则跳过;如果暂停拖动到中间,则seek
 | 
	
		
			
				|  |  |                  if currentPlayRecordIndex == -1 {
 | 
	
		
			
				|  |  |                      let second = CMTimeGetSeconds(currentT) - recordedAudio.startTime
 | 
	
		
			
				|  |  | -                    recordPlayer?.seek(to: CMTime(value: CMTimeValue(second), timescale: 100), toleranceBefore: CMTime(value: 1, timescale: 1000), toleranceAfter: CMTime(value: 1, timescale: 1000), completionHandler: {[weak recordPlayer] finished in
 | 
	
		
			
				|  |  | +                    recordPlayer?.seek(to: CMTime(value: CMTimeValue(second), timescale: 100), toleranceBefore: CMTime(value: 1, timescale: 1000), toleranceAfter: CMTime(value: 1, timescale: 1000), completionHandler: { finished in
 | 
	
		
			
				|  |  |                          if finished {
 | 
	
		
			
				|  |  | -                            recordPlayer?.play()
 | 
	
		
			
				|  |  | +                            DispatchQueue.main.async {[weak self] in
 | 
	
		
			
				|  |  | +                                self?.recordPlayer?.play()
 | 
	
		
			
				|  |  | +                            }
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  |                      })
 | 
	
		
			
				|  |  |                      currentPlayRecordIndex = shouldPlayRecordIndex
 | 
	
		
			
				|  |  |                      hadPrepareToPlayRecord = true
 | 
	
		
			
				|  |  | -                    BFLog(1, message: "录音开始播放2 \(second), \(recordPlayer?.currentItem?.duration)")
 | 
	
		
			
				|  |  | +                    BFLog(1, message: "录音开始播放2, \(second), \(CMTimeGetSeconds(recordPlayer?.currentItem?.duration ?? .zero))")
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              
 | 
	
	
		
			
				|  | @@ -447,7 +468,7 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  |      func play(){
 | 
	
		
			
				|  |  |          BFLog(1, message: "开始播放")
 | 
	
		
			
				|  |  | -        assetPlayer?.volume = 0.02
 | 
	
		
			
				|  |  | +        assetPlayer?.volume = 0.2
 | 
	
		
			
				|  |  |          movie?.startProcessing()
 | 
	
		
			
				|  |  |          isNormalPlaying = true
 | 
	
		
			
				|  |  |          let second = assetPlayer?.currentItem?.currentTime()
 | 
	
	
		
			
				|  | @@ -604,8 +625,21 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  | -    func drewRecordProgessLable(){
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  | +    func drawOrUpdateRecordProgessLable(){
 | 
	
		
			
				|  |  | +        progessSildeBackV.subviews.forEach { vv in
 | 
	
		
			
				|  |  | +            vv.removeFromSuperview()
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        DispatchQueue.main.async {[weak self] in
 | 
	
		
			
				|  |  | +            if let totalDur = self?.asset?.duration, totalDur > 0, let list = self?.recordList {
 | 
	
		
			
				|  |  | +                let width = self?.progessSildeBackV.width ?? 0
 | 
	
		
			
				|  |  | +                let height = self?.progessSildeBackV.height ?? 0
 | 
	
		
			
				|  |  | +                list.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 = UIColor.hexColor(hexadecimal: "#28BE67")
 | 
	
		
			
				|  |  | +                    self?.progessSildeBackV.addSubview(lineV)
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 |