浏览代码

摄像头缩略图

harry 3 年之前
父节点
当前提交
3416576be1

+ 37 - 8
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenCameraManager.swift

@@ -100,6 +100,7 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
         videoModel = PQEditVisionTrackMaterialsModel()
         videoModel = PQEditVisionTrackMaterialsModel()
         videoModel.thumImgs = [UIImage]()
         videoModel.thumImgs = [UIImage]()
         videoModel.timelineIn = currentAssetProgress.seconds
         videoModel.timelineIn = currentAssetProgress.seconds
+        videoModel.timelineOut = currentAssetProgress.seconds
         currVideoIndex = recordItem?.videoStickers.count ?? 0
         currVideoIndex = recordItem?.videoStickers.count ?? 0
         
         
         
         
@@ -123,7 +124,7 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
             wself.videoModel.timelineOut = currDur.seconds
             wself.videoModel.timelineOut = currDur.seconds
             wself.recordProgressCallBack?(currDur)
             wself.recordProgressCallBack?(currDur)
             wself.updateUI(progress: currDur)
             wself.updateUI(progress: currDur)
-//            BFLog(1, message: "currTime \(dur.seconds), \(wself.currentAssetProgress.seconds)")
+            BFLog(1, message: "currTime: \(wself.currentAssetProgress.seconds)")
         })
         })
         RunLoop.current.add(timerr!, forMode: .common)
         RunLoop.current.add(timerr!, forMode: .common)
     }
     }
@@ -143,12 +144,26 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
                     if let finalPath = PQBridgeObject.p_setupFileRename(vpath), finalPath.count > 0 {
                     if let finalPath = PQBridgeObject.p_setupFileRename(vpath), finalPath.count > 0 {
                         let dur = AVURLAsset(url: URL(fileURLWithPath: finalPath))
                         let dur = AVURLAsset(url: URL(fileURLWithPath: finalPath))
                         BFLog(1, message: "拍摄文件时长: \(dur.duration.seconds)")
                         BFLog(1, message: "拍摄文件时长: \(dur.duration.seconds)")
-                        wself.videoModel.timelineOut += dur.duration.seconds
+                        wself.videoModel.timelineOut = wself.videoModel.timelineIn + dur.duration.seconds
                         wself.videoModel.locationPath = finalPath
                         wself.videoModel.locationPath = finalPath
-                        wself.recordEndCallBack?(true, wself.videoModel)
+                        wself.currentAssetProgress = CMTime(seconds: wself.videoModel.timelineOut, preferredTimescale: 1000)
                     }else{
                     }else{
+                        // 录制失败后恢复原样
+                        wself.videoModel.timelineOut = wself.videoModel.timelineIn
+                        wself.currentAssetProgress = CMTime(seconds: wself.videoModel.timelineOut, preferredTimescale: 1000)
+                        wself.recordItem?.thumbImgs.removeAll(where: { img in
+                            wself.videoModel.thumImgs?.contains(img) ?? false
+                        })
+                        wself.videoModel.thumImgs?.removeAll()
+                        
+                        wself.addNewThumb()
                         cShowHUB(superView: nil, msg: "录制失败,未能生成文件")
                         cShowHUB(superView: nil, msg: "录制失败,未能生成文件")
                     }
                     }
+                    DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
+                        wself.updateUI(progress:  wself.currentAssetProgress)
+                    }
+                    wself.recordEndCallBack?(true, wself.videoModel)
+
                 }
                 }
             }
             }
             
             
@@ -157,6 +172,14 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
         })
         })
     }
     }
     
     
+    override func play() {
+        camera?.pauseCapture()
+    }
+    
+    override func pause() {
+        camera?.resumeCameraCapture()
+    }
+    
     override func clean() {
     override func clean() {
         filter.removeTarget(movieWrite)
         filter.removeTarget(movieWrite)
         filter.removeTarget(rendView)
         filter.removeTarget(rendView)
@@ -166,12 +189,18 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
     
     
     // MARK: - 私有方法
     // MARK: - 私有方法
     func updateUI(progress:CMTime){
     func updateUI(progress:CMTime){
-        progreddL?.text = CMTimeGetSeconds(progress).formatDurationToHMS()
-//        cameraProgressV?.collectionV.contentOffset = CGPoint(x: progress.seconds * 70 / 5.0, y: 0)
-        cameraProgressV?.addThumbImages()
+        DispatchQueue.main.async {[weak self] in
+            guard let wself = self else { return }
+            
+            wself.progreddL?.text = CMTimeGetSeconds(progress).formatDurationToHMS()
+            if wself.recordItem?.thumbImgs.count ?? 0 > 0 {
+                wself.cameraProgressV?.updateCellWidth(index: wself.recordItem!.thumbImgs.count - 1, progress: progress)
+            }
+            
+        }
     }
     }
     
     
-    func updateThumb(){
+    func addNewThumb(){
         if let progressThumV = cameraProgressV {
         if let progressThumV = cameraProgressV {
 //            progressThumV.collectionV.reloadData()
 //            progressThumV.collectionV.reloadData()
             progressThumV.addThumbImages()
             progressThumV.addThumbImages()
@@ -212,7 +241,7 @@ extension BFRecordScreenCameraManager : GPUImageVideoCameraDelegate {
                 recordItem?.thumbImgs.append(img)
                 recordItem?.thumbImgs.append(img)
                 videoModel.thumImgs?.append(img)
                 videoModel.thumImgs?.append(img)
                 currVideoThumImagesNum += 1
                 currVideoThumImagesNum += 1
-                updateThumb()
+                addNewThumb()
             }
             }
         }
         }
     }
     }

+ 101 - 112
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -169,7 +169,7 @@ public class BFRecordScreenController: BFBaseViewController {
     var currentAssetProgress: CMTime = .zero
     var currentAssetProgress: CMTime = .zero
     {
     {
         didSet {
         didSet {
-            BFLog(3, message: "currentAssetProgress=\(currentAssetProgress.seconds)")
+            BFLog(1, message: "currentAssetProgress=\(currentAssetProgress.seconds)")
             rscurrentManager.currentAssetProgress = currentAssetProgress
             rscurrentManager.currentAssetProgress = currentAssetProgress
         }
         }
     } // 当前素材播放的进度
     } // 当前素材播放的进度
@@ -562,11 +562,83 @@ public class BFRecordScreenController: BFBaseViewController {
             self?.NeoNuiAPPID = appkey
             self?.NeoNuiAPPID = appkey
             self?.NeoNuiToken = token
             self?.NeoNuiToken = token
         }
         }
+        
+        initlizeRecordManager()
+        
+        view.backgroundColor = .black
+        view.addSubview(collectionView)
+        
+        fetchVideo()
+        
+        view.addSubview(bottomeView)
+//        view.addSubview(subtitleLabel)
+        view.addSubview(playBtn)
+        view.addSubview(avatarView)
+//        view.addSubview(openCameraBtn)
+//        view.addSubview(drawPinBtn)
+        view.addSubview(subtitleBtn)
+        view.addSubview(soundSettingBtn)
+        view.addSubview(subtitleSettingView)
 
 
-        // MARK: - 录音机初始化
+        view.addSubview(audioSettingView)
+
+        bottomeView.addSubview(progreddL)
+        //        view.addSubview(toolV)
+        bottomeView.addSubview(recordBtn)
+        bottomeView.addSubview(deleteRecordBtn)
+        bottomeView.addSubview(withDrawBtn)
+        //        bottomeView.addSubview(changeVoiceBtn)
+        bottomeView.addSubview(progressThumV)
+        bottomeView.addSubview(cameraProgressThumV)
+
+        avatarView.recordEndCallBack = { _, materialsModel in
+            BFLog(message: "新录制完成::::\(materialsModel?.locationPath ?? "")")
+        }
 
 
-        recorderManager = BFVoiceRecordManager()
 
 
+        // 字幕设置回调
+        subtitleSettingView.subtitleSettingCallBack = { [weak self] subtitileModel in
+
+            self?.setSubtitleStyle(settingModel: subtitileModel.setting)
+            // mdf by ak 这里是设置字幕开关回调
+            if self?.subTitleBtnClickHandle != nil {
+                self?.subTitleBtnClickHandle!(subtitileModel.setting.subtitleIsShow)
+            }
+        }
+        // 编辑字幕完成
+        subtitleEditView.editSubtitleDone = { [weak self] newtext, index in
+
+            // 更新缓存数据
+            if index < (self?.itemModels[self?.currItemModelIndex ?? 0].titleStickers.count ?? 0) {
+                if newtext.count == 0 {
+                    // 删除数据
+                    BFLog(message: "清空字幕操作要删除原字幕 sticker 数据")
+                    self?.itemModels[self?.currItemModelIndex ?? 0].titleStickers.remove(at: index)
+                } else {
+                    // 更新数据
+                    self?.itemModels[self?.currItemModelIndex ?? 0].titleStickers[index].text = newtext
+                }
+            }
+
+            self?.setSubtitleStyle(settingModel: (self?.subtitleSettingView.subtitle.setting)!)
+        }
+
+        layoutsubview()
+
+        view.addSubview(subtitleEditView)
+
+        if !SWNetRequest.isNetReachabled() {
+            cShowHUB(superView: view, msg: "网络不佳,字幕可能无法生成")
+        }
+        if PQENVUtil.shared.channel == "Development" {
+            view.addSubview(neoNuiDebugLabel)
+            view.addSubview(audioQueueRecoderLabel)
+        }
+    }
+    
+    // MARK: - 录音机初始化
+    func initlizeRecordManager() {
+        recorderManager = BFVoiceRecordManager()
         // 录音进度
         // 录音进度
         recorderManager?.recorderProgrossHandle = { [weak self] progress in
         recorderManager?.recorderProgrossHandle = { [weak self] progress in
 //            BFLog(1, message: "curr:录音进度--\(progress),\(self?.isRecording ?? false)")
 //            BFLog(1, message: "curr:录音进度--\(progress),\(self?.isRecording ?? false)")
@@ -627,7 +699,7 @@ public class BFRecordScreenController: BFBaseViewController {
                     return
                     return
                 }
                 }
                 newSubtitle.timelineIn = currentVoice.startCMTime + CMTime(seconds: Float64((((payload?["begin_time"]) as? Int) ?? 0) + 300) / 1000.0, preferredTimescale: 1000)
                 newSubtitle.timelineIn = currentVoice.startCMTime + CMTime(seconds: Float64((((payload?["begin_time"]) as? Int) ?? 0) + 300) / 1000.0, preferredTimescale: 1000)
-                newSubtitle.timelineOut = currentVoice.startCMTime + CMTime(seconds: Float64(((payload?["time"]) as? Int) ?? 0) / 1000.0, preferredTimescale: 1000)
+                newSubtitle.timelineOut = currentVoice.startCMTime + CMTime(seconds: Float64((((payload?["time"]) as? Int) ?? 0) - 10) / 1000.0, preferredTimescale: 1000)
                 newSubtitle.audioFilePath = currentVoice.wavFilePath
                 newSubtitle.audioFilePath = currentVoice.wavFilePath
                 BFLog(3, message: "字幕回调-字幕返回begin:\(((payload?["begin_time"]) as? Int) ?? 0),timelineIn:\(newSubtitle.timelineIn.seconds), end:\(((payload?["time"]) as? Int) ?? 0),timelineOut:\(newSubtitle.timelineOut.seconds)")
                 BFLog(3, message: "字幕回调-字幕返回begin:\(((payload?["begin_time"]) as? Int) ?? 0),timelineIn:\(newSubtitle.timelineIn.seconds), end:\(((payload?["time"]) as? Int) ?? 0),timelineOut:\(newSubtitle.timelineOut.seconds)")
                 if (newSubtitle.timelineIn - currentVoice.startCMTime).seconds > 0.1 {
                 if (newSubtitle.timelineIn - currentVoice.startCMTime).seconds > 0.1 {
@@ -710,7 +782,7 @@ public class BFRecordScreenController: BFBaseViewController {
                 event.deletedTittles = deletedTitlesTemp
                 event.deletedTittles = deletedTitlesTemp
                 wself.events.append(event)
                 wself.events.append(event)
 
 
-                if wself.itemModels[wself.currItemModelIndex].mediaType == .Image {
+                if wself.itemModels[wself.currItemModelIndex].mediaType != .Video {
                     var duration: CMTime = .zero
                     var duration: CMTime = .zero
                     wself.itemModels[wself.currItemModelIndex].voiceStickers.forEach { temp in
                     wself.itemModels[wself.currItemModelIndex].voiceStickers.forEach { temp in
                         BFLog(1, message: "录制结束-最终:\(temp.wavFilePath ?? "")-\(temp.startCMTime.seconds)-\(temp.endCMTime.seconds)-\(temp.endCMTime.seconds - temp.startCMTime.seconds)")
                         BFLog(1, message: "录制结束-最终:\(temp.wavFilePath ?? "")-\(temp.startCMTime.seconds)-\(temp.endCMTime.seconds)-\(temp.endCMTime.seconds - temp.startCMTime.seconds)")
@@ -764,75 +836,6 @@ public class BFRecordScreenController: BFBaseViewController {
             }
             }
         }
         }
 
 
-        view.backgroundColor = .black
-        view.addSubview(collectionView)
-        
-        fetchVideo()
-        
-        view.addSubview(bottomeView)
-//        view.addSubview(subtitleLabel)
-        view.addSubview(playBtn)
-        view.addSubview(avatarView)
-//        view.addSubview(openCameraBtn)
-//        view.addSubview(drawPinBtn)
-        view.addSubview(subtitleBtn)
-        view.addSubview(soundSettingBtn)
-        view.addSubview(subtitleSettingView)
-
-        view.addSubview(audioSettingView)
-
-        bottomeView.addSubview(progreddL)
-        //        view.addSubview(toolV)
-        bottomeView.addSubview(recordBtn)
-        bottomeView.addSubview(deleteRecordBtn)
-        bottomeView.addSubview(withDrawBtn)
-        //        bottomeView.addSubview(changeVoiceBtn)
-        bottomeView.addSubview(progressThumV)
-        bottomeView.addSubview(cameraProgressThumV)
-
-        avatarView.recordEndCallBack = { _, materialsModel in
-            BFLog(message: "新录制完成::::\(materialsModel?.locationPath ?? "")")
-        }
-
-
-        // 字幕设置回调
-        subtitleSettingView.subtitleSettingCallBack = { [weak self] subtitileModel in
-
-            self?.setSubtitleStyle(settingModel: subtitileModel.setting)
-            // mdf by ak 这里是设置字幕开关回调
-            if self?.subTitleBtnClickHandle != nil {
-                self?.subTitleBtnClickHandle!(subtitileModel.setting.subtitleIsShow)
-            }
-        }
-        // 编辑字幕完成
-        subtitleEditView.editSubtitleDone = { [weak self] newtext, index in
-
-            // 更新缓存数据
-            if index < (self?.itemModels[self?.currItemModelIndex ?? 0].titleStickers.count ?? 0) {
-                if newtext.count == 0 {
-                    // 删除数据
-                    BFLog(message: "清空字幕操作要删除原字幕 sticker 数据")
-                    self?.itemModels[self?.currItemModelIndex ?? 0].titleStickers.remove(at: index)
-                } else {
-                    // 更新数据
-                    self?.itemModels[self?.currItemModelIndex ?? 0].titleStickers[index].text = newtext
-                }
-            }
-
-            self?.setSubtitleStyle(settingModel: (self?.subtitleSettingView.subtitle.setting)!)
-        }
-
-        layoutsubview()
-
-        view.addSubview(subtitleEditView)
-
-        if !SWNetRequest.isNetReachabled() {
-            cShowHUB(superView: view, msg: "网络不佳,字幕可能无法生成")
-        }
-        if PQENVUtil.shared.channel == "Development" {
-            view.addSubview(neoNuiDebugLabel)
-            view.addSubview(audioQueueRecoderLabel)
-        }
     }
     }
 
 
     @objc func editSubtitle() {
     @objc func editSubtitle() {
@@ -1178,7 +1181,7 @@ public class BFRecordScreenController: BFBaseViewController {
             wself.recorderManager?.voiceModel = model
             wself.recorderManager?.voiceModel = model
             BFLog(3, message: "开始录制-开始:currentAssetProgress=\(wself.currentAssetProgress.seconds),cuInde=\(wself.currItemModelIndex),\(model)")
             BFLog(3, message: "开始录制-开始:currentAssetProgress=\(wself.currentAssetProgress.seconds),cuInde=\(wself.currItemModelIndex),\(model)")
             wself.recorderManager?.startRecord()
             wself.recorderManager?.startRecord()
-//            wself.recorderManager?.audioRecorder?.startNeoNui(wself.NeoNuiToken ?? "", appid: wself.NeoNuiAPPID ?? "")
+            wself.recorderManager?.audioRecorder?.startNeoNui(wself.NeoNuiToken ?? "", appid: wself.NeoNuiAPPID ?? "")
 
 
         }
         }
         // 开始时间
         // 开始时间
@@ -1415,7 +1418,7 @@ public class BFRecordScreenController: BFBaseViewController {
             /// 重绘录音进度视图
             /// 重绘录音进度视图
             resetAllIndirectionView()
             resetAllIndirectionView()
             // 如果是图片需重置播放按钮
             // 如果是图片需重置播放按钮
-            if itemModel.mediaType == .Image {
+            if itemModel.mediaType != .Video {
                 playBtn.isSelected = itemModels[currItemModelIndex].voiceStickers.count <= 0
                 playBtn.isSelected = itemModels[currItemModelIndex].voiceStickers.count <= 0
                 playBtn.isHidden = playBtn.isSelected
                 playBtn.isHidden = playBtn.isSelected
             }
             }
@@ -1454,24 +1457,9 @@ public class BFRecordScreenController: BFBaseViewController {
             play()
             play()
         }
         }
     }
     }
-
-    @objc func sliderTouchBegan(sender _: UISlider) {
-        isDragingProgressSlder = true
-        pause()
-    }
-
-    @objc func sliderTouchEnded(sender: UISlider) {
-        changeProgress(progress: sender.value)
-        isDragingProgressSlder = false
-        currentPlayRecordIndex = -1
-        BFLog(3, message: "重置播放index-\(#function) = \(currentPlayRecordIndex),\(sender.value)")
-        hadPrepareToPlayRecord = false
-    }
-
-    @objc func sliderValueDidChanged(sender: UISlider) {
-        changeProgress(progress: sender.value)
-    }
-
+    
+    // MARK: - 进度条拖动回调
+    
     func thumbViewEnded(progress: Float) {
     func thumbViewEnded(progress: Float) {
         changeProgress(progress: progress)
         changeProgress(progress: progress)
         isDragingProgressSlder = false
         isDragingProgressSlder = false
@@ -1865,8 +1853,9 @@ public class BFRecordScreenController: BFBaseViewController {
         hadPrepareToPlayRecord = false
         hadPrepareToPlayRecord = false
 
 
         // 暂停状态
         // 暂停状态
-        playBtn.isSelected = (rscurrentManager.recordItem?.mediaType == .Image && rscurrentManager.recordItem?.voiceStickers.count ?? -1 <= 0)
+        playBtn.isSelected = (rscurrentManager.recordItem?.mediaType != .Video && rscurrentManager.recordItem?.voiceStickers.count ?? -1 <= 0)
         playBtn.isHidden = playBtn.isSelected
         playBtn.isHidden = playBtn.isSelected
+        rscurrentManager.pause()
     }
     }
 
 
     func fetchVideo() {
     func fetchVideo() {
@@ -1879,19 +1868,19 @@ public class BFRecordScreenController: BFBaseViewController {
                     itemModel.coverPath = asset.localPath
                     itemModel.coverPath = asset.localPath
                 }
                 }
                 itemModels.append(itemModel)
                 itemModels.append(itemModel)
-                if index == 0 {
-                    if asset.mediaType == .video {
-                        itemModel.fetchAVUrlAssetCallBack = { [weak self, weak itemModel] in
-                            DispatchQueue.main.async { [weak self, weak itemModel] in
-                                self?.progressThumV.recordItem = itemModel
-                                self?.progressThumV.isHidden = false
-                                self?.recordBtn.isEnabled = true
-                            }
-                        }
-                    } else {
-                        recordBtn.isEnabled = true
-                    }
-                }
+//                if index == 0 {
+//                    if asset.mediaType == .video {
+//                        itemModel.fetchAVUrlAssetCallBack = { [weak self, weak itemModel] in
+//                            DispatchQueue.main.async { [weak self, weak itemModel] in
+////                                self?.progressThumV.recordItem = itemModel
+//                                self?.progressThumV.isHidden = false
+//                                self?.recordBtn.isEnabled = true
+//                            }
+//                        }
+//                    } else {
+//                        recordBtn.isEnabled = true
+//                    }
+//                }
             }
             }
         }else {
         }else {
             let itemModel = BFRecordItemModel()
             let itemModel = BFRecordItemModel()
@@ -1904,7 +1893,7 @@ public class BFRecordScreenController: BFBaseViewController {
         collectionView.reloadData()
         collectionView.reloadData()
 
 
         // 暂停状态--如果是图片素材同时没有录音文件时不显示播放按钮
         // 暂停状态--如果是图片素材同时没有录音文件时不显示播放按钮
-        playBtn.isSelected = (itemModels.first?.mediaType == .Image && (itemModels.first?.voiceStickers.count ?? 0) <= 0)
+        playBtn.isSelected = (itemModels.first?.mediaType != .Video && (itemModels.first?.voiceStickers.count ?? 0) <= 0)
         playBtn.isHidden = playBtn.isSelected
         playBtn.isHidden = playBtn.isSelected
     }
     }
 
 
@@ -2136,7 +2125,7 @@ extension BFRecordScreenController: UICollectionViewDelegate, UICollectionViewDa
             }
             }
             cell?.addData()
             cell?.addData()
             if item.mediaType != .Camera {
             if item.mediaType != .Camera {
-                wself.progressThumV.recordItem = item
+                wself.progressThumV.recordItem?.coverImg = item.coverImg
                 wself.progressThumV.isHidden = false
                 wself.progressThumV.isHidden = false
             }
             }
         }
         }
@@ -2197,7 +2186,7 @@ extension BFRecordScreenController: UICollectionViewDelegate, UICollectionViewDa
 
 
             let recordItem = itemModels[currItemModelIndex]
             let recordItem = itemModels[currItemModelIndex]
             // 暂停状态--如果是图片素材同时没有录音文件时不显示播放按钮
             // 暂停状态--如果是图片素材同时没有录音文件时不显示播放按钮
-            playBtn.isSelected = (recordItem.mediaType == .Image && recordItem.voiceStickers.count <= 0)
+            playBtn.isSelected = (recordItem.mediaType != .Video && recordItem.voiceStickers.count <= 0)
             playBtn.isHidden = playBtn.isSelected
             playBtn.isHidden = playBtn.isSelected
             // 重绘录音区域
             // 重绘录音区域
             progressThumV.recordItem = recordItem
             progressThumV.recordItem = recordItem
@@ -2310,7 +2299,7 @@ public extension BFRecordScreenController {
         } else {
         } else {
             currentAssetProgress = recordStartPlayTime + CMTime(seconds: progress, preferredTimescale: 1000)
             currentAssetProgress = recordStartPlayTime + CMTime(seconds: progress, preferredTimescale: 1000)
         }
         }
-        BFLog(1, message: "图片录音进度:\(progress),currentAssetProgress=\(currentAssetProgress.seconds),\(itemModels[currItemModelIndex].materialDuraion)")
+//        BFLog(1, message: "图片录音进度:\(progress),currentAssetProgress=\(currentAssetProgress.seconds),\(itemModels[currItemModelIndex].materialDuraion)")
         if itemModels[currItemModelIndex].mediaType == .Image {
         if itemModels[currItemModelIndex].mediaType == .Image {
             /// 重置进度
             /// 重置进度
             resetCurrentProgress()
             resetCurrentProgress()

+ 12 - 10
BFRecordScreenKit/Classes/RecordScreen/View/Cell/BFVideoCoverViewCell.swift

@@ -18,16 +18,18 @@ open class BFVideoCoverViewCell: BFImageCoverViewCell {
     
     
     public override func addData() {
     public override func addData() {
         super.addData()
         super.addData()
-        let degress = degressFromVideoFile(asset: (recordItem?.videoAsset)!)
-        switch degress {
-        case 90:
-            playView.setInputRotation(GPUImageRotationMode(rawValue: 2), at: 0)
-        case 180:
-            playView.setInputRotation(GPUImageRotationMode(rawValue: 7), at: 0)
-        case 270:
-            playView.setInputRotation(GPUImageRotationMode(rawValue: 1), at: 0)
-        default:
-            break
+        if let asset = recordItem?.videoAsset {
+            let degress = degressFromVideoFile(asset: asset)
+            switch degress {
+            case 90:
+                playView.setInputRotation(GPUImageRotationMode(rawValue: 2), at: 0)
+            case 180:
+                playView.setInputRotation(GPUImageRotationMode(rawValue: 7), at: 0)
+            case 270:
+                playView.setInputRotation(GPUImageRotationMode(rawValue: 1), at: 0)
+            default:
+                break
+            }
         }
         }
     }
     }
 
 

+ 54 - 25
BFRecordScreenKit/Classes/RecordScreen/View/ProgressView/BFCameraProgressView.swift

@@ -7,6 +7,8 @@
 
 
 import Foundation
 import Foundation
 import BFCommonKit
 import BFCommonKit
+import BFUIKit
+import CoreMedia
 
 
 class BFCameraProgressView: BFProgressBaseView {
 class BFCameraProgressView: BFProgressBaseView {
     
     
@@ -16,15 +18,22 @@ class BFCameraProgressView: BFProgressBaseView {
         flowLayout.minimumInteritemSpacing = 0
         flowLayout.minimumInteritemSpacing = 0
         flowLayout.scrollDirection = .horizontal
         flowLayout.scrollDirection = .horizontal
         flowLayout.itemSize = CGSize(width: self.frame.width, height: self.frame.height)
         flowLayout.itemSize = CGSize(width: self.frame.width, height: self.frame.height)
-        
+        flowLayout.headerReferenceSize = CGSize(width: cScreenWidth / 2.0, height: 50)
+        flowLayout.footerReferenceSize = CGSize(width: cScreenWidth / 2.0, height: 50)
+
         let cc = UICollectionView(frame: CGRect(x: 0, y: 0, width: self.width, height: self.height), collectionViewLayout: flowLayout)
         let cc = UICollectionView(frame: CGRect(x: 0, y: 0, width: self.width, height: self.height), collectionViewLayout: flowLayout)
         cc.delegate = self
         cc.delegate = self
         cc.dataSource = self
         cc.dataSource = self
         cc.bounces = false
         cc.bounces = false
+        cc.register(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier:  String(describing: UICollectionReusableView.self))
+        cc.register(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier:  String(describing: UICollectionReusableView.self))
         cc.register(UICollectionViewCell.self, forCellWithReuseIdentifier: String(describing: UICollectionViewCell.self))
         cc.register(UICollectionViewCell.self, forCellWithReuseIdentifier: String(describing: UICollectionViewCell.self))
         cc.showsVerticalScrollIndicator = false
         cc.showsVerticalScrollIndicator = false
         cc.showsHorizontalScrollIndicator = false
         cc.showsHorizontalScrollIndicator = false
+//        cc.contentInset = UIEdgeInsets(top: 0, left: cScreenWidth / 2, bottom: 0, right: cScreenWidth / 2)
         cc.backgroundColor = UIColor.clear
         cc.backgroundColor = UIColor.clear
+        cc.decelerationRate = .fast
+        
         return cc
         return cc
     }()
     }()
     
     
@@ -32,6 +41,7 @@ class BFCameraProgressView: BFProgressBaseView {
         super.init(frame: frame)
         super.init(frame: frame)
 
 
         addSubview(collectionV)
         addSubview(collectionV)
+        insertSubview(collectionV, belowSubview: line)
         
         
     }
     }
 
 
@@ -42,8 +52,20 @@ class BFCameraProgressView: BFProgressBaseView {
     /// 添加缩略图
     /// 添加缩略图
     /// - Parameter images:
     /// - Parameter images:
     func addThumbImages() {
     func addThumbImages() {
-        DispatchQueue.main.async {
-            self.collectionV.reloadData()
+        if let count = recordItem?.thumbImgs.count, count > 0 {
+            DispatchQueue.main.async {
+                self.collectionV.insertItems(at: [IndexPath(row: count - 1, section: 0)])
+            }
+        }
+    }
+    
+    func updateCellWidth(index:Int, progress:CMTime){
+        if let count = recordItem?.thumbImgs.count, count > 0 {
+            collectionV.reloadItems(at: [IndexPath(row: count - 1, section: 0)])
+            let p = CGPoint(x: progress.seconds * 70 / 5.0, y: 0)
+            collectionV.contentOffset = p
+        }else {
+            collectionV.reloadData()
         }
         }
     }
     }
 }
 }
@@ -53,29 +75,43 @@ extension BFCameraProgressView: UICollectionViewDelegateFlowLayout, UICollection
         return recordItem?.thumbImgs.count ?? 0
         return recordItem?.thumbImgs.count ?? 0
     }
     }
     
     
+    func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
+        if kind == UICollectionView.elementKindSectionHeader || kind == UICollectionView.elementKindSectionFooter{
+            let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: String(describing: UICollectionReusableView.self), for: indexPath)
+            header.backgroundColor = .yellow
+            return header
+        }
+        return UICollectionReusableView()
+    }
+    
     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
         var size : CGSize = .zero
         var size : CGSize = .zero
         if let img = recordItem?.thumbImgs[indexPath.row] {
         if let img = recordItem?.thumbImgs[indexPath.row] {
             if let sticker = recordItem?.videoStickers.first(where: { m in
             if let sticker = recordItem?.videoStickers.first(where: { m in
-                m.thumImgs?.contains(img) as? Bool ?? false
+                m.thumImgs?.contains(img) ?? false
             }) {
             }) {
                 if img == sticker.thumImgs!.last {
                 if img == sticker.thumImgs!.last {
-                    size = CGSize(width: (sticker.timelineOut - sticker.timelineIn) * 70.0 / 5.0, height: 50)
+                    size = CGSize(width: ((sticker.timelineOut - sticker.timelineIn) * 70.0 / 5.0).truncatingRemainder(dividingBy: 70.0), height: 50)
+                    if (size.width < 0){
+                        BFLog(1, message: "errror")
+                        size = .zero
+                    }
+//                    BFLog(1, message: "currsize \(size), \(indexPath.row), \(sticker.timelineOut), \(sticker.timelineIn)")
                 }else{
                 }else{
                     size = CGSize(width: 70.0, height: 50)
                     size = CGSize(width: 70.0, height: 50)
                 }
                 }
             }
             }
         }
         }
-        BFLog(1, message: "size \(size), \(indexPath.row)")
         return size
         return size
     }
     }
     
     
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: UICollectionViewCell.self), for: indexPath)
         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: UICollectionViewCell.self), for: indexPath)
+        cell.contentView.clipsToBounds = true
         var imgview : UIImageView? = cell.contentView.viewWithTag(13000) as? UIImageView
         var imgview : UIImageView? = cell.contentView.viewWithTag(13000) as? UIImageView
         if  imgview == nil {
         if  imgview == nil {
             imgview = UIImageView(frame: CGRect(x: 0, y: 0, width: 70, height: 50))
             imgview = UIImageView(frame: CGRect(x: 0, y: 0, width: 70, height: 50))
-            imgview?.contentMode = .scaleAspectFit
+            imgview?.contentMode = .scaleAspectFill
             imgview?.tag = 13000
             imgview?.tag = 13000
             cell.contentView.addSubview(imgview!)
             cell.contentView.addSubview(imgview!)
         }
         }
@@ -88,39 +124,32 @@ extension BFCameraProgressView: UICollectionViewDelegateFlowLayout, UICollection
 
 
 extension BFCameraProgressView {
 extension BFCameraProgressView {
     func scrollViewDidScroll(_ scrollView: UIScrollView) {
     func scrollViewDidScroll(_ scrollView: UIScrollView) {
-        let totalW = recordItem?.mediaType == .Video ? (scrollView.contentSize.width - width) : (CGFloat(recordItem?.materialDuraion.seconds ?? 0) * thumbImageWidth / 2.0)
-        if recordItem?.mediaType == .Video {
-            if isDrag {
-                dragScrollProgressHandle?(false, totalW > 0 ? min(Float(scrollView.contentOffset.x / totalW), 1) : 0)
-            }
-        } else if recordItem?.mediaType == .Image {
-            if isDrag {
-                if scrollView.contentOffset.x > ((CGFloat(recordItem?.materialDuraion.seconds ?? 0) * thumbImageWidth / 2.0) + 0.5) {
-                    scrollView.contentOffset = CGPoint(x: (CGFloat(recordItem?.materialDuraion.seconds ?? 0) * thumbImageWidth / 2.0) + 0.5, y: 0)
-                }
-                dragScrollProgressHandle?(false, totalW > 0 ? min(Float(scrollView.contentOffset.x / totalW), 1) : 0)
-            }
+        if isDrag {
+            let totalW = (scrollView.contentOffset.x + cScreenWidth / 2.0) / scrollView.contentSize.width
+            
+            dragScrollProgressHandle?(false,Float(min(1, max(0, totalW))))
         }
         }
     }
     }
 
 
     func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
     func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
         isDrag = true
         isDrag = true
-        let totalW = recordItem?.mediaType == .Video ? (scrollView.contentSize.width - width) : (CGFloat(recordItem?.materialDuraion.seconds ?? 0) * thumbImageWidth / 2.0)
+        let totalW = (scrollView.contentOffset.x + cScreenWidth / 2.0) / scrollView.contentSize.width
         dragStartHandle?()
         dragStartHandle?()
-        dragScrollProgressHandle?(true, totalW > 0 ? min(Float(scrollView.contentOffset.x / totalW), 1) : 0)
+        
+        dragScrollProgressHandle?(true,Float(min(1, max(0, totalW))))
     }
     }
 
 
     func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
     func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
         if !decelerate {
         if !decelerate {
-            let totalW = recordItem?.mediaType == .Video ? (scrollView.contentSize.width - width) : (CGFloat(recordItem?.materialDuraion.seconds ?? 0) * thumbImageWidth / 2.0)
+            let totalW = (scrollView.contentOffset.x + cScreenWidth / 2.0) / scrollView.contentSize.width
             isDrag = false
             isDrag = false
-            dragEndHandle?(totalW > 0 ? min(Float(scrollView.contentOffset.x / totalW), 1) : 0)
+            dragEndHandle?(Float(min(1, max(0, totalW))))
         }
         }
     }
     }
 
 
     func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
     func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
-        let totalW = recordItem?.mediaType == .Video ? (scrollView.contentSize.width - width) : (CGFloat(recordItem?.materialDuraion.seconds ?? 0) * thumbImageWidth / 2.0)
+        let totalW = (scrollView.contentOffset.x + cScreenWidth / 2.0) / scrollView.contentSize.width
         isDrag = false
         isDrag = false
-        dragEndHandle?(totalW > 0 ? min(Float(scrollView.contentOffset.x / totalW), 1) : 0)
+        dragEndHandle?(Float(min(1, max(0, totalW))))
     }
     }
 }
 }

+ 10 - 5
BFRecordScreenKit/Classes/RecordScreen/View/ProgressView/BFProgressBaseView.swift

@@ -19,16 +19,21 @@ class BFProgressBaseView: UIView {
 
 
     let thumbImageWidth: CGFloat = 70.0
     let thumbImageWidth: CGFloat = 70.0
     
     
+    lazy var line : UIView = {
+        let v = UIView()        
+        v.backgroundColor = .white
+        v.layer.borderColor = UIColor.black.cgColor
+        v.layer.borderWidth = 0.3
+        v.layer.cornerRadius = 1.5
+        
+        return v
+    }()
+    
     func addThumbImages(images: [UIImage]){}
     func addThumbImages(images: [UIImage]){}
     
     
     override init(frame: CGRect) {
     override init(frame: CGRect) {
         super.init(frame: frame)
         super.init(frame: frame)
 
 
-        let line = UIView()
-        line.backgroundColor = .white
-        line.layer.borderColor = UIColor.black.cgColor
-        line.layer.borderWidth = 0.3
-        line.layer.cornerRadius = 1.5
         addSubview(line)
         addSubview(line)
         line.snp.makeConstraints { make in
         line.snp.makeConstraints { make in
             make.width.equalTo(3)
             make.width.equalTo(3)

+ 26 - 22
BFRecordScreenKit/Classes/RecordScreen/View/ProgressView/BFVideoThumbProgressView.swift

@@ -161,36 +161,40 @@ class BFVideoThumbProgressView: BFProgressBaseView {
     /// - Parameter images: <#images description#>
     /// - Parameter images: <#images description#>
     override func addThumbImages(images: [UIImage]) {
     override func addThumbImages(images: [UIImage]) {
         DispatchQueue.main.async { [weak self] in
         DispatchQueue.main.async { [weak self] in
-            self?.progressView.contentView.subviews.forEach { subview in
+            guard let wself = self else { return }
+            wself.progressView.contentView.subviews.forEach { subview in
                 if subview is UIImageView {
                 if subview is UIImageView {
                     subview.removeFromSuperview()
                     subview.removeFromSuperview()
                 }
                 }
             }
             }
             if images.count > 0 {
             if images.count > 0 {
-                if let wself = self {
-                    if wself.lastImg != nil, wself.lastImg?.superview != nil {
-                        wself.lastImg?.removeFromSuperview()
-                    }
-                    for (i, img) in images.enumerated() {
-                        let iv = UIImageView(image: img)
-                        iv.contentMode = .scaleAspectFill
-                        iv.clipsToBounds = true
-                        wself.progressView.contentView.insertSubview(iv, belowSubview: wself.progessIndicateBackV)
-                        iv.snp.makeConstraints { make in
-                            make.left.equalTo(CGFloat(i) * CGFloat(wself.thumbImageWidth) + wself.width * 0.5)
-                            make.top.bottom.equalToSuperview()
-                            make.height.equalTo(50)
-                            make.width.equalTo(wself.thumbImageWidth)
-                        }
-                        wself.lastImg = iv
+                if wself.lastImg != nil, wself.lastImg?.superview != nil {
+                    wself.lastImg?.removeFromSuperview()
+                }
+                for (i, img) in images.enumerated() {
+                    let iv = UIImageView(image: img)
+                    iv.contentMode = .scaleAspectFill
+                    iv.clipsToBounds = true
+                    wself.progressView.contentView.insertSubview(iv, belowSubview: wself.progessIndicateBackV)
+                    iv.snp.makeConstraints { make in
+                        make.left.equalTo(CGFloat(i) * CGFloat(wself.thumbImageWidth) + wself.width * 0.5)
+                        make.top.bottom.equalToSuperview()
+                        make.height.equalTo(50)
+                        make.width.equalTo(wself.thumbImageWidth)
                     }
                     }
-                    if wself.recordItem?.mediaType == .Image {
-                        // 图片需要动态修改宽度
-                        wself.lastImg?.snp.makeConstraints { make in
-                            make.right.equalTo(wself.width * -0.5)
-                        }
+                    
+                    wself.lastImg = iv
+                }
+                BFLog(1, message: "last img \(wself.lastImg), \(images.count)")
+                wself.progressView.contentView.setNeedsLayout()
+                wself.progressView.contentView.layoutIfNeeded()
+                if wself.recordItem?.mediaType == .Image {
+                    // 图片需要动态修改宽度
+                    wself.lastImg?.snp.makeConstraints { make in
+                        make.right.equalTo(wself.width * -0.5)
                     }
                     }
                 }
                 }
+            
             }
             }
         }
         }
     }
     }