|  | @@ -26,6 +26,8 @@ struct WithDrawModel {
 | 
	
		
			
				|  |  |      var deletedTittles: [PQEditSubTitleModel]?
 | 
	
		
			
				|  |  |      //
 | 
	
		
			
				|  |  |      var deletedCameras: [PQEditVisionTrackMaterialsModel]?
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    var recordItem: BFRecordItemModel
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -185,6 +187,7 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |              soundSettingBtn.isHidden = isRecording
 | 
	
		
			
				|  |  |              recordBtn.setTitle(isRecording ? "record_pause".BFLocale : (currMediaType == .Camera ? "record_lz".BFLocale : "record_ly".BFLocale), for: .normal)
 | 
	
		
			
				|  |  |              recordBtn.backgroundColor = UIColor.hexColor(hexadecimal: "#389AFF", alpha: isRecording ? 0.6 : 1)
 | 
	
		
			
				|  |  | +            cameraFlipBtn.isHidden = !(!isRecording && (currMediaType == .Camera))
 | 
	
		
			
				|  |  |  //            if !isRecording {
 | 
	
		
			
				|  |  |  //                BFLog(1, message: "stop")
 | 
	
		
			
				|  |  |  //            }
 | 
	
	
		
			
				|  | @@ -208,6 +211,11 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |      public var isNormalPlaying = false { // 是否正在播放
 | 
	
		
			
				|  |  |          didSet {
 | 
	
		
			
				|  |  |              withDrawBtn.isHidden = isNormalPlaying
 | 
	
		
			
				|  |  | +            subtitleBtn.isHidden = isNormalPlaying
 | 
	
		
			
				|  |  | +            soundSettingBtn.isHidden = isNormalPlaying
 | 
	
		
			
				|  |  | +            withDrawBtn.isHidden = isNormalPlaying
 | 
	
		
			
				|  |  | +            recordBtn.isHidden = isNormalPlaying
 | 
	
		
			
				|  |  | +            cameraFlipBtn.isHidden = !(!isNormalPlaying && (currMediaType == .Camera) && !isDragingProgressSlder)
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -236,7 +244,10 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |      // 行为记录,方便撤销
 | 
	
		
			
				|  |  |      var events = [WithDrawModel]() {
 | 
	
		
			
				|  |  |          didSet {
 | 
	
		
			
				|  |  | -            withDrawBtn.isEnabled = (events.count != 0)
 | 
	
		
			
				|  |  | +            DispatchQueue.main.async {[weak self] in
 | 
	
		
			
				|  |  | +                guard let wself = self else { return }
 | 
	
		
			
				|  |  | +                wself.withDrawBtn.isEnabled = (wself.events.count != 0)
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -1084,12 +1095,6 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  // ***********处理冲突的录音部分资源 end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                // 添加撤销记录点
 | 
	
		
			
				|  |  | -                var event = WithDrawModel(type: 2, timestamp: model.startCMTime)
 | 
	
		
			
				|  |  | -                event.deletedVoices = deletedVoices
 | 
	
		
			
				|  |  | -                event.deletedTittles = deletedTitlesTemp
 | 
	
		
			
				|  |  | -                wself.events.append(event)
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |                  if wself.currMediaType != .Video {
 | 
	
		
			
				|  |  |                      var duration: CMTime = .zero
 | 
	
		
			
				|  |  |                      if wself.currMediaType == .Image{
 | 
	
	
		
			
				|  | @@ -1378,7 +1383,7 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |              let model = itemModels[currItemModelIndex].voiceStickers[isStopAtRecordRange]
 | 
	
		
			
				|  |  |              itemModels[currItemModelIndex].voiceStickers.remove(at: isStopAtRecordRange)
 | 
	
		
			
				|  |  |              indirectionView?.deleteItem(index: isStopAtRecordRange)
 | 
	
		
			
				|  |  | -            var event = WithDrawModel(type: 3, timestamp: currentAssetProgress, deletedVoices: [model])
 | 
	
		
			
				|  |  | +            var event = WithDrawModel(type: 3, timestamp: currentAssetProgress, deletedVoices: [model], recordItem: rscurrentManager.recordItem!)
 | 
	
		
			
				|  |  |              event.deletedTittles = deleteTitles(voiceModel: model)
 | 
	
		
			
				|  |  |              events.append(event)
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -1440,7 +1445,13 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |              BFLog(3, message: "开始录制-开始:currentAssetProgress=\(wself.currentAssetProgress.seconds),cuInde=\(wself.currItemModelIndex),\(model)")
 | 
	
		
			
				|  |  |              wself.recorderManager?.startRecord()
 | 
	
		
			
				|  |  |              wself.recorderManager?.audioRecorder?.startNeoNui(wself.NeoNuiToken ?? "", appid: wself.NeoNuiAPPID ?? "")
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +            // 添加撤销记录点
 | 
	
		
			
				|  |  | +            let event = WithDrawModel(type: 2, timestamp: model.startCMTime, recordItem: wself.rscurrentManager.recordItem!)
 | 
	
		
			
				|  |  | +            wself.events.append(event)
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  |          // 开始时间
 | 
	
		
			
				|  |  |          beginOnStartBtn = true
 | 
	
		
			
				|  |  |          isRecording = true
 | 
	
	
		
			
				|  | @@ -1457,10 +1468,6 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |          // 录制中不显示播放按钮
 | 
	
		
			
				|  |  |          playBtn.isSelected = true
 | 
	
		
			
				|  |  |          playBtn.isHidden = true
 | 
	
		
			
				|  |  | -        if currMediaType == .Camera {
 | 
	
		
			
				|  |  | -            cameraFlipBtn.isHidden = true
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  |          let cell = collectionView.cellForItem(at: IndexPath(item: currItemModelIndex, section: 0)) as? BFImageCoverViewCell
 | 
	
		
			
				|  |  |          if cell?.contentView.viewWithTag(100_100)?.superview == nil {
 | 
	
	
		
			
				|  | @@ -1475,8 +1482,6 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          if currMediaType == .Video {
 | 
	
		
			
				|  |  |              pause()
 | 
	
		
			
				|  |  | -        }else if currMediaType == .Camera {
 | 
	
		
			
				|  |  | -            cameraFlipBtn.isHidden = false
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  |          beginOnStartBtn = false
 | 
	
	
		
			
				|  | @@ -1568,6 +1573,8 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |      // 撤销
 | 
	
		
			
				|  |  |      @objc func withdrawAction() {
 | 
	
		
			
				|  |  |          pause()
 | 
	
		
			
				|  |  | +        recoverRecord()
 | 
	
		
			
				|  |  | +        return
 | 
	
		
			
				|  |  |          if let action = events.last {
 | 
	
		
			
				|  |  |              let jumpTime = action.timestamp
 | 
	
		
			
				|  |  |              if action.type == 2 {
 | 
	
	
		
			
				|  | @@ -1762,7 +1769,6 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |              pause()
 | 
	
		
			
				|  |  |              searchStopAtRecordRange()
 | 
	
		
			
				|  |  |          } else {
 | 
	
		
			
				|  |  | -            events.append(WithDrawModel(type: 1, timestamp: currentAssetProgress))
 | 
	
		
			
				|  |  |              changeWithDrawBtnLayout(0)
 | 
	
		
			
				|  |  |              play()
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -1799,7 +1805,7 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |                  guard let wself = self else { return }
 | 
	
		
			
				|  |  |                  
 | 
	
		
			
				|  |  |                  if isStart {
 | 
	
		
			
				|  |  | -                    wself.events.append(WithDrawModel(type: 0, timestamp: wself.currentAssetProgress))
 | 
	
		
			
				|  |  | +                    wself.events.append(WithDrawModel(type: 0, timestamp: wself.currentAssetProgress, recordItem: wself.rscurrentManager.recordItem!))
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                  wself.isDragingProgressSlder = true
 | 
	
	
		
			
				|  | @@ -1883,9 +1889,14 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |                  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)){
 | 
	
		
			
				|  |  | +            if (currMediaType == .Camera && (endTime! - currentAssetProgress).seconds < 2 * 5 / 70.0)
 | 
	
		
			
				|  |  | +                || (currMediaType == .Image && ((endTime! - currentAssetProgress).seconds < 2 * 2.0 / 70.0))
 | 
	
		
			
				|  |  | +                || (currMediaType == .Image && ((endTime! - currentAssetProgress).seconds < 2 * (rscurrentManager.recordItem!.materialDuraion.seconds / Double(rscurrentManager.recordItem!.thumbImgs.count)) / 70.0)){
 | 
	
		
			
				|  |  |                  canInsertVideo = true
 | 
	
		
			
				|  |  | +                
 | 
	
		
			
				|  |  | +                changeProgress(changCMTime: endTime!)
 | 
	
		
			
				|  |  | +                progressThumV.progress = endTime!.seconds
 | 
	
		
			
				|  |  | +                
 | 
	
		
			
				|  |  |                  BFLog(1, message: "可以插入录音")
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              updateRecordBtnStatus(true)
 | 
	
	
		
			
				|  | @@ -1905,14 +1916,14 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |      func updatePlayBtnStatus(){
 | 
	
		
			
				|  |  |          switch currMediaType {
 | 
	
		
			
				|  |  |          case .Image:
 | 
	
		
			
				|  |  | -            playBtn.isSelected = ((rsimanager.recordItem?.voiceStickers.count ?? 0) <= 0)
 | 
	
		
			
				|  |  | +            playBtn.isSelected = ((rsimanager.recordItem?.voiceStickers.count ?? -1) <= 0)
 | 
	
		
			
				|  |  |              playBtn.isHidden = playBtn.isSelected
 | 
	
		
			
				|  |  |              
 | 
	
		
			
				|  |  |          case .Video:
 | 
	
		
			
				|  |  |              playBtn.isSelected = false
 | 
	
		
			
				|  |  |              playBtn.isHidden = false
 | 
	
		
			
				|  |  |          case .Camera:
 | 
	
		
			
				|  |  | -            playBtn.isSelected = isEndPlay ? true : ((rscmanager.recordItem?.voiceStickers.count ?? 0) <= 0)
 | 
	
		
			
				|  |  | +            playBtn.isSelected = isEndPlay ? true : ((rscmanager.recordItem?.voiceStickers.count ?? -1) <= 0)
 | 
	
		
			
				|  |  |              playBtn.isHidden = playBtn.isSelected
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -1921,11 +1932,12 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |          let su = show ?? false
 | 
	
		
			
				|  |  |          switch currMediaType {
 | 
	
		
			
				|  |  |          case .Image:
 | 
	
		
			
				|  |  | -            recordBtn.isHidden = isEndPlay ? false : su
 | 
	
		
			
				|  |  | +            recordBtn.isHidden = (isEndPlay || canInsertVideo) ? false : su
 | 
	
		
			
				|  |  |          case .Video:
 | 
	
		
			
				|  |  |              recordBtn.isHidden = isEndPlay ? true : su
 | 
	
		
			
				|  |  |          case .Camera:
 | 
	
		
			
				|  |  | -            recordBtn.isHidden = isEndPlay ? false : su
 | 
	
		
			
				|  |  | +            recordBtn.isHidden = (isEndPlay || canInsertVideo) ? false : su
 | 
	
		
			
				|  |  | +            cameraFlipBtn.isHidden = recordBtn.isHidden
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  |          deleteRecordBtn.isHidden = isEndPlay ? true : !(recordBtn.isHidden)
 | 
	
	
		
			
				|  | @@ -1940,15 +1952,19 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  | -    //
 | 
	
		
			
				|  |  | +    // 重新加载数据
 | 
	
		
			
				|  |  |      func recoverRecord() {
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  | +        if let action = events.last {
 | 
	
		
			
				|  |  | +            // 重置播放器进度,按钮状态,缩略图展示,当前进度
 | 
	
		
			
				|  |  | +            rscurrentManager.recordItem = action.recordItem
 | 
	
		
			
				|  |  | +            changeProgress(changCMTime: action.timestamp)
 | 
	
		
			
				|  |  | +            progressThumV.progress = action.timestamp.seconds
 | 
	
		
			
				|  |  | +            searchStopAtRecordRange()
 | 
	
		
			
				|  |  | +            resetAllIndirectionView()
 | 
	
		
			
				|  |  | +            
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  | -    // 重新加载数据
 | 
	
		
			
				|  |  | -    func reloadData(){
 | 
	
		
			
				|  |  | -        // 重置播放器进度,按钮状态,缩略图展示,当前进度
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      // MARK: - 权限申请
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -2183,6 +2199,7 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |      func play() {
 | 
	
		
			
				|  |  |          BFLog(1, message: "开始播放 \(currentAssetProgress.seconds)")
 | 
	
		
			
				|  |  |          recorderManager?.voiceModel = nil
 | 
	
		
			
				|  |  | +        events.append(WithDrawModel(type: 1, timestamp: currentAssetProgress, recordItem: rscurrentManager.recordItem!))
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          itemModels[currItemModelIndex].titleStickers.sort { m1, m2 in
 | 
	
		
			
				|  |  |              CMTimeCompare(m1.timelineIn, m2.timelineIn) < 0
 | 
	
	
		
			
				|  | @@ -2225,8 +2242,7 @@ public class BFRecordScreenController: BFBaseViewController {
 | 
	
		
			
				|  |  |          hadPrepareToPlayRecord = false
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          // 暂停状态
 | 
	
		
			
				|  |  | -        playBtn.isSelected = (currMediaType == .Image && rscurrentManager.recordItem?.voiceStickers.count ?? -1 <= 0) || (currMediaType == .Camera && isEndPlay)
 | 
	
		
			
				|  |  | -        playBtn.isHidden = playBtn.isSelected
 | 
	
		
			
				|  |  | +        updatePlayBtnStatus()
 | 
	
		
			
				|  |  |          rscurrentManager.pause()
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 |