浏览代码

自拍文件旋转问题fix

harry 3 年之前
父节点
当前提交
9cab2eaa86

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

@@ -123,7 +123,7 @@ public class BFRecordScreenController: BFBaseViewController {
             }
             
             if let cell = collectionView.cellForItem(at: IndexPath(item: currItemModelIndex, section: 0)) as? BFImageCoverViewCell {
-                if (cell as? BFCameraCoverViewCell) != nil {
+                if currMediaType == .Camera {
                     cell.playView.setInputRotation(GPUImageRotationMode(rawValue: 2), at: 0)
                     progressThumV.isHidden = true
 
@@ -134,8 +134,10 @@ public class BFRecordScreenController: BFBaseViewController {
                     }
                     
                 } else {
-//                    cell.playView.setInputRotation(GPUImageRotationMode(rawValue: 0), at: 0)
                     progressThumV.isHidden = false
+                    if currMediaType == .Video {
+                        (cell as? BFVideoCoverViewCell)?.rotationView()
+                    }
                 }
                 rscurrentManager.playView = cell.playView
             }
@@ -144,7 +146,7 @@ public class BFRecordScreenController: BFBaseViewController {
             rscurrentManager.recordPlayer = recordPlayer
             rscurrentManager.progressThumV = progressThumV
             rscurrentManager.dele = self
-
+            progressThumV.recordItem = itemModel
             rscurrentManager.recordItem = itemModel
             rscurrentManager.resetEnv()
 
@@ -1277,7 +1279,6 @@ 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 ?? "")
-
         }
         // 开始时间
         beginOnStartBtn = true
@@ -1998,19 +1999,44 @@ public class BFRecordScreenController: BFBaseViewController {
                 itemModel.index = index
                 if asset.title == "record.camera"{
                     itemModel.mediaType = .Camera
-
                 }else{
                     itemModel.initOriginData(phasset: asset)
                     if asset.mediaType != .video {
                         itemModel.coverPath = asset.localPath
                     }
+                    itemModel.fetchCoverImgCallBack = { [weak self, weak itemModel] _ in
+                        guard let wself = self, let item = itemModel else {
+                            return
+                        }
+                        if let cell = wself.collectionView.cellForItem(at: IndexPath(item: wself.currItemModelIndex, section: 0)) as? BFImageCoverViewCell, cell.recordItem?.localPath == item.localPath {
+                            cell.addData()
+                            if item.mediaType != .Camera {
+                                wself.progressThumV.recordItem?.coverImg = item.coverImg
+                                wself.progressThumV.isHidden = false
+                            }
+                        }
+                    }
+                    itemModel.fetchPlayItemCallBack = { [weak self, weak itemModel] item in
+                        guard let wself = self, let item = itemModel else {
+                            return
+                        }
+                        if let cell = wself.collectionView.cellForItem(at: IndexPath(item: wself.currItemModelIndex, section: 0)) as? BFImageCoverViewCell, cell.recordItem?.localPath == item.localPath {
+                            guard itemModel != nil else {
+                                BFLog(message: "视频获取失败:\(item.index )")
+                                cShowHUB(superView: nil, msg: "option_fail_obtain".BFLocale)
+                                return
+                            }
+                            wself.rscurrentManager.resetEnv()
+                        }
+                    }
                 }
                 indexPaths.append(IndexPath(row: itemModels.count, section: 0))
                 itemModels.append(itemModel)
             }
         }
-        collectionView.insertItems(at: indexPaths)
-        collectionView.contentOffset = CGPoint(x: cScreenWidth * CGFloat(lastCount) , y: 0.0)
+        collectionView.reloadData()
+//        collectionView.contentOffset = CGPoint(x: cScreenWidth * CGFloat(lastCount) , y: 0.0)
+        collectionView.scrollToItem(at: IndexPath(row: lastCount, section: 0), at: .left, animated: false)
         DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {[weak self] in
             guard let wself = self else { return }
             
@@ -2256,27 +2282,6 @@ extension BFRecordScreenController: UICollectionViewDelegate, UICollectionViewDa
             break
         }
         
-        recordItem.fetchCoverImgCallBack = { [weak self, weak cell, weak recordItem] _ in
-            guard let wself = self, let item = recordItem else {
-                return
-            }
-            cell?.addData()
-            if item.mediaType != .Camera {
-                wself.progressThumV.recordItem?.coverImg = item.coverImg
-                wself.progressThumV.isHidden = false
-            }
-        }
-        recordItem.fetchPlayItemCallBack = { [weak self, weak recordItem] item in
-            guard let wself = self else {
-                return
-            }
-            guard item != nil else {
-                BFLog(message: "视频获取失败:\(recordItem?.index ?? 0)")
-                cShowHUB(superView: nil, msg: "option_fail_obtain".BFLocale)
-                return
-            }
-            wself.rscurrentManager.resetEnv()
-        }
         cell.btnClickHandle = { [weak self] _, _ in
             guard let wself = self else {
                 return

+ 6 - 0
BFRecordScreenKit/Classes/RecordScreen/View/Cell/BFVideoCoverViewCell.swift

@@ -8,6 +8,7 @@
 
 import UIKit
 import GPUImage
+import BFCommonKit
 
 open class BFVideoCoverViewCell: BFImageCoverViewCell {
 
@@ -18,8 +19,12 @@ open class BFVideoCoverViewCell: BFImageCoverViewCell {
     
     public override func addData() {
         super.addData()
+    }
+    
+    public func rotationView(){
         if let asset = recordItem?.videoAsset {
             let degress = degressFromVideoFile(asset: asset)
+//            BFLog(1, message: "degress:\(degress)")
             switch degress {
             case 90:
                 playView.setInputRotation(GPUImageRotationMode(rawValue: 2), at: 0)
@@ -28,6 +33,7 @@ open class BFVideoCoverViewCell: BFImageCoverViewCell {
             case 270:
                 playView.setInputRotation(GPUImageRotationMode(rawValue: 1), at: 0)
             default:
+                playView.setInputRotation(GPUImageRotationMode(rawValue: 0), at: 0)
                 break
             }
         }

+ 1 - 1
BFRecordScreenKit/Classes/RecordScreen/View/ProgressView/BFVideoThumbProgressView.swift

@@ -229,7 +229,7 @@ class BFVideoThumbProgressView: BFProgressBaseView {
         if recordItem?.mediaType == .Video {
             if let second = recordItem?.materialDuraion.seconds, second > 0 {
                 let w = progressView.contentSize.width - width
-                BFLog(message: "录音进度--指示器:progress=\(progress),duration=\(second),w=\(w),perW=\(Double(w) / second),totalW:\(progress * Double(w) / second)")
+                BFLog(1, message: "录音进度--指示器:progress=\(progress),duration=\(second),w=\(w),perW=\(Double(w) / second),totalW:\(progress * Double(w) / second)")
                 progressView.contentOffset = CGPoint(x: progress * Double(w) / second, y: 0)
             }
         } else if recordItem?.mediaType == .Image {