浏览代码

Merge branch 'master' of https://git.yishihui.com/iOS/BFRecordScreenKit

* 'master' of https://git.yishihui.com/iOS/BFRecordScreenKit:
  1.调整图片素材播放逻辑
harry 3 年之前
父节点
当前提交
ea2ed0bb55

+ 5 - 13
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -475,6 +475,8 @@ public class BFRecordScreenController: BFBaseViewController {
                         }
                         sself.itemModels[sself.currItemModelIndex].materialDuraion = Double(String(format: "%.3f", duration)) ?? 0
                         self?.isEndPlay = true
+                        // 录制结束显示播放按钮
+                        (sself.collectionView.cellForItem(at: IndexPath(item: sself.currItemModelIndex, section: 0)) as? BFImageCoverViewCell)?.playBtn.isSelected = sself.itemModels[sself.currItemModelIndex].voiceStickers.count <= 0
                     }
                     DispatchQueue.main.async { [weak self] in
                         // 录音完,重绘撤销按钮,更新录音按钮,
@@ -884,7 +886,6 @@ public class BFRecordScreenController: BFBaseViewController {
         if !avatarView.isHidden {
             avatarView.beginRecord()
         }
-        
         if itemModels[currItemModelIndex].mediaType == .VIDEO {
             if !movieIsProcessing {
                 movie?.startProcessing()
@@ -892,10 +893,9 @@ public class BFRecordScreenController: BFBaseViewController {
             }
             assetPlayer?.volume = 0
             assetPlayer?.play()
-            
-            // 暂停状态
-            (collectionView.cellForItem(at: IndexPath(item: currItemModelIndex, section: 0)) as? BFImageCoverViewCell)?.playBtn.isSelected = true
         }
+        // 录制中不显示播放按钮
+        (collectionView.cellForItem(at: IndexPath(item: currItemModelIndex, section: 0)) as? BFImageCoverViewCell)?.playBtn.isSelected = true
     }
     
     @objc func endRecord() {
@@ -1293,7 +1293,7 @@ public class BFRecordScreenController: BFBaseViewController {
         assetPlayer?.seek(to: currentAssetProgress, toleranceBefore: CMTime(value: 1, timescale: 1_000_000), toleranceAfter: CMTime(value: 1, timescale: 1_000_000), completionHandler: { _ in
         })
         // 暂停状态
-        (collectionView.cellForItem(at: IndexPath(item: currItemModelIndex, section: 0)) as? BFImageCoverViewCell)?.playBtn.isSelected = false
+        (collectionView.cellForItem(at: IndexPath(item: currItemModelIndex, section: 0)) as? BFImageCoverViewCell)?.playBtn.isSelected = (itemModels[currItemModelIndex].mediaType == .IMAGE && itemModels[currItemModelIndex].voiceStickers.count <= 0)
     }
     
     func fetchVideo() {
@@ -1581,10 +1581,6 @@ extension BFRecordScreenController: UICollectionViewDelegate, UICollectionViewDa
         if page != currItemModelIndex {
             // 暂停
             pause()
-            // 暂停状态
-            let lastCell: BFImageCoverViewCell? = collectionView.cellForItem(at: IndexPath(item: currItemModelIndex, section: 0)) as? BFImageCoverViewCell
-            lastCell?.playBtn.isSelected = false
-
             events.append(WithDrawModel(type: 0, timestamp: currentAssetProgress.seconds))
             // 重设撤销栈
             itemModels[currItemModelIndex].events = events
@@ -1601,8 +1597,6 @@ extension BFRecordScreenController: UICollectionViewDelegate, UICollectionViewDa
             // 更新缩略图
             progressThumV.isHidden = false
             progreddL.text = "00:00"
-            
-            
             // 重置指针
             currentAssetProgress = CMTime(seconds: 0, preferredTimescale: 1000)
             searchStopAtRecordRange()
@@ -1612,8 +1606,6 @@ extension BFRecordScreenController: UICollectionViewDelegate, UICollectionViewDa
             
             searchStopAtRecordRange()
             changeWithDrawBtnLayout(false)
-            
-            // 重置到首位
             pauseTime = 0
             if recordItem.mediaType == .VIDEO {
                 reloadMaterial()

+ 3 - 1
BFRecordScreenKit/Classes/RecordScreen/View/BFImageCoverViewCell.swift

@@ -6,9 +6,9 @@
 //  Copyright © 2021 BytesFlow. All rights reserved.
 //
 
+import BFUIKit
 import GPUImage
 import UIKit
-import BFUIKit
 
 open class BFImageCoverViewCell: UICollectionViewCell {
     var btnClickHandle: ((_ sender: UIButton, _ recordItem: BFRecordItemModel?) -> Void)?
@@ -76,6 +76,8 @@ open class BFImageCoverViewCell: UICollectionViewCell {
         picture.addTarget(filter)
         filter.addTarget(playView)
         picture.processImage()
+        // 暂停状态--如果是图片素材同时没有录音文件时不显示播放按钮
+        playBtn.isSelected = (recordItem?.mediaType == .IMAGE && (recordItem?.voiceStickers.count ?? 0) <= 0)
     }
 
     public func addLayout() {