Browse Source

图片不加载的问题

harry 3 years ago
parent
commit
3152c73dfd

+ 25 - 16
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -122,24 +122,26 @@ public class BFRecordScreenController: BFBaseViewController {
                 break
             }
             
-            if let cell = collectionView.cellForItem(at: IndexPath(item: currItemModelIndex, section: 0)) as? BFImageCoverViewCell {
+            let cell = collectionView.cellForItem(at: IndexPath(item: currItemModelIndex, section: 0)) as? BFImageCoverViewCell
+            if  cell != nil {
                 if currMediaType == .Camera {
-                    cell.playView.setInputRotation(GPUImageRotationMode(rawValue: 2), at: 0)
+                    cell!.playView.setInputRotation(GPUImageRotationMode(rawValue: 2), at: 0)
                     progressThumV.isHidden = true
 
                     rscmanager.rendView.removeFromSuperview()
-                    cell.playView.addSubview(rscmanager.rendView)
+                    cell!.playView.addSubview(rscmanager.rendView)
                     rscmanager.rendView.snp.makeConstraints { make in
                         make.edges.equalToSuperview()
                     }
                     
                 } else {
                     progressThumV.isHidden = false
-                    if currMediaType == .Video {
-                        (cell as? BFVideoCoverViewCell)?.rotationView()
+                    if currMediaType == .Image{
+                        // 解决不能第一时间获取缩略图时的问题
+                        cell!.addData()
                     }
                 }
-                rscurrentManager.playView = cell.playView
+                rscurrentManager.playView = cell!.playView
             }
             
             rscurrentManager.progreddL = progreddL
@@ -149,7 +151,9 @@ public class BFRecordScreenController: BFBaseViewController {
             progressThumV.recordItem = itemModel
             rscurrentManager.recordItem = itemModel
             rscurrentManager.resetEnv()
-
+            if currMediaType == .Video {
+                (cell as? BFVideoCoverViewCell)?.rotationView()
+            }
         }
     }
     
@@ -2004,11 +2008,11 @@ public class BFRecordScreenController: BFBaseViewController {
                     if asset.mediaType != .video {
                         itemModel.coverPath = asset.localPath
                     }
-                    itemModel.fetchCoverImgCallBack = { [weak self, weak itemModel] _ in
+                    itemModel.fetchCoverImgCallBack = { [weak self, weak itemModel] img 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 {
+                        if let cell = wself.collectionView.cellForItem(at: IndexPath(item: wself.currItemModelIndex, section: 0)) as? BFImageCoverViewCell, cell.recordItem?.coverImg == img {
                             cell.addData()
                             if item.mediaType != .Camera {
                                 wself.progressThumV.recordItem?.coverImg = item.coverImg
@@ -2016,17 +2020,17 @@ public class BFRecordScreenController: BFBaseViewController {
                             }
                         }
                     }
-                    itemModel.fetchPlayItemCallBack = { [weak self, weak itemModel] item in
+                    itemModel.fetchPlayItemCallBack = { [weak self, weak itemModel] _ in
                         guard let wself = self, let item = itemModel else {
                             return
                         }
+                        guard item.playItem != nil  else {
+                            BFLog(message: "视频获取失败:\(item.index)")
+                            cShowHUB(superView: nil, msg: "option_fail_obtain".BFLocale)
+                            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()
+                                wself.rscurrentManager.resetEnv()
                         }
                     }
                 }
@@ -2294,6 +2298,11 @@ extension BFRecordScreenController: UICollectionViewDelegate, UICollectionViewDa
 
     public func collectionView(_: UICollectionView, didSelectItemAt _: IndexPath) {}
 
+    public func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
+        if let currCell = cell as? BFVideoCoverViewCell {
+            currCell.rotationView()
+        }
+    }
     public func scrollViewWillBeginDragging(_: UIScrollView) {
         BFLog(1, message: "开始滚动")
         if currMediaType == .Camera && rscurrentManager.recordItem?.voiceStickers.count == 0{