Browse Source

数据保护;
滚动结束后切换资源

harry 3 years ago
parent
commit
0b1f2f0aba

+ 20 - 4
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -1470,9 +1470,13 @@ public class BFRecordScreenController: BFBaseViewController {
 
     // 通过缩略图进度条控制播放进度
     func changeProgress(progress: Float) {
+        var newProgress = progress
+        if newProgress.isNaN || newProgress.isFinite {
+            newProgress = 0
+        }
         if itemModels[currItemModelIndex].mediaType == .VIDEO {
             if let duration = assetPlayer?.currentItem?.duration {
-                currentAssetProgress = CMTime(value: CMTimeValue(progress * Float(CMTimeGetSeconds(duration)) * 1000), timescale: 1000)
+                currentAssetProgress = CMTime(value: CMTimeValue(newProgress * Float(CMTimeGetSeconds(duration)) * 1000), timescale: 1000)
                 DispatchQueue.main.async { [weak self] in
                     self!.progreddL.text = String(format: "%@", CMTimeGetSeconds(self!.currentAssetProgress).formatDurationToHMS())
                 }
@@ -1481,11 +1485,11 @@ public class BFRecordScreenController: BFBaseViewController {
             }
         } else {
             if itemModels[currItemModelIndex].materialDuraion >= 0 {
-                currentAssetProgress = CMTime(value: CMTimeValue(progress * Float(itemModels[currItemModelIndex].materialDuraion) * 1000), timescale: 1000)
+                currentAssetProgress = CMTime(value: CMTimeValue(newProgress * Float(itemModels[currItemModelIndex].materialDuraion) * 1000), timescale: 1000)
                 DispatchQueue.main.async { [weak self] in
                     self?.progreddL.text = String(format: "%@", CMTimeGetSeconds(self!.currentAssetProgress).formatDurationToHMS())
                 }
-                BFLog(message: "progress = \(progress),currentAssetProgress = \(currentAssetProgress.seconds),materialDuraion = \(itemModels[currItemModelIndex].materialDuraion)")
+                BFLog(message: "progress = \(newProgress),currentAssetProgress = \(currentAssetProgress.seconds),materialDuraion = \(itemModels[currItemModelIndex].materialDuraion)")
             }
         }
     }
@@ -1593,7 +1597,19 @@ extension BFRecordScreenController: UICollectionViewDelegate, UICollectionViewDa
 
     public func collectionView(_: UICollectionView, didSelectItemAt _: IndexPath) {}
 
-    public func scrollViewDidScroll(_ scrollView: UIScrollView) {
+    public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
+        endScrollItem(scrollView)
+    }
+    
+    public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
+        if !decelerate {
+            endScrollItem(scrollView)
+        }
+    }
+    
+    func endScrollItem(_ scrollView: UIScrollView) {
+//    public func scrollViewDidScroll(_ scrollView: UIScrollView) {
+        BFLog(1, message: "滚动结束")
         let page = Int((scrollView.contentOffset.x + scrollView.frame.width / 2) / scrollView.frame.width)
         if page != currItemModelIndex {
             // 暂停