소스 검색

append image thumb and update materialDuraion

wenweiwei 3 년 전
부모
커밋
dac926fcd9

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

@@ -8,12 +8,12 @@
 
 import BFCommonKit
 import BFMediaKit
+import BFNetRequestKit
 import BFUIKit
 import Foundation
 import GPUImage
 import Photos
 import UIKit
-import BFNetRequestKit
 
 struct WithDrawModel {
     var type: Int // 0:拖动; 1:预览播放暂停 2: 录音结束  3: 删除录音  4: 删除字幕
@@ -127,7 +127,7 @@ public class BFRecordScreenController: BFBaseViewController {
                     sself.itemModels[sself.currItemModelIndex].voiceStickers.forEach { _ in
                         duration = duration + (Double(model.duration ?? "0") ?? 0)
                     }
-                    sself.itemModels[sself.currItemModelIndex].materialDuraion = duration
+                    sself.itemModels[sself.currItemModelIndex].materialDuraion = Double(String(format: "%.3f", duration)) ?? 0
                     sself.currentAssetProgress = CMTime(seconds: duration, preferredTimescale: 1000)
                     model.endTime = sself.currentAssetProgress.seconds
                     self?.isEndPlay = true
@@ -478,8 +478,8 @@ public class BFRecordScreenController: BFBaseViewController {
         layoutsubview()
 
         view.addSubview(subtitleEditView)
-        
-        if(!SWNetRequest.isNetReachabled()){
+
+        if !SWNetRequest.isNetReachabled() {
             cShowHUB(superView: view, msg: "网络不佳,字幕可能无法生成")
         }
     }
@@ -1240,7 +1240,7 @@ public class BFRecordScreenController: BFBaseViewController {
                 DispatchQueue.main.async { [weak self] in
                     self?.progreddL.text = String(format: "%@", CMTimeGetSeconds(self!.currentAssetProgress).formatDurationToHMS())
                 }
-                BFLog(message: "progress = \(progress),currentAssetProgress = \(currentAssetProgress)")
+                BFLog(message: "progress = \(progress),currentAssetProgress = \(currentAssetProgress.seconds),materialDuraion = \(itemModels[currItemModelIndex].materialDuraion)")
             }
         }
     }
@@ -1403,6 +1403,10 @@ public extension BFRecordScreenController {
     /// 处理图片音频的播放
     func imageRecordPlay() {
         if itemModels[currItemModelIndex].mediaType == .IMAGE {
+            if itemModels[currItemModelIndex].materialDuraion <= 0 || currentAssetProgress.seconds >= itemModels[currItemModelIndex].materialDuraion {
+                (collectionView.cellForItem(at: IndexPath(item: currItemModelIndex, section: 0)) as? BFImageCoverViewCell)?.playBtn.isSelected = false
+                return
+            }
             isNormalPlaying = true
             playRecord(at: currentAssetProgress, periodicTimeObserver: { [weak self] currentT, currentItem in
                 BFLog(message: "播放一段进度:\(currentT),\(currentItem)")

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

@@ -151,6 +151,34 @@ class BFVideoThumbProgressView: UIView {
         }
     }
 
+    func appendThumb(progress: Double = 0) {
+        let count: Int = Int((progress < 1 ? progress * 100 : progress) / 2)
+        if recordItem?.mediaType == .IMAGE, thumbImgs.count < (count - 5) {
+            guard let image = recordItem?.coverImg else {
+                return
+            }
+            var lastiv = UIImageView()
+            let lastIndex = thumbImgs.count - 1
+            for i in lastIndex ... lastIndex + 10 {
+                let iv = UIImageView(image: image)
+                iv.contentMode = .scaleAspectFill
+                iv.clipsToBounds = true
+                progressView.contentView.addSubview(iv)
+                iv.snp.makeConstraints { make in
+                    make.left.equalTo(CGFloat(i) * CGFloat(thumbImageWidth) + width * 0.5)
+                    make.top.bottom.equalToSuperview()
+                    make.height.equalTo(50)
+                    make.width.equalTo(thumbImageWidth)
+                }
+                lastiv = iv
+                thumbImgs.append(image)
+            }
+            lastiv.snp.makeConstraints { make in
+                make.right.equalTo(width * -0.5)
+            }
+        }
+    }
+
     /// 更新进度
     /// - Parameter progress: <#progress description#>
     func updateProgress(progress: Double = 0) {
@@ -161,7 +189,8 @@ class BFVideoThumbProgressView: UIView {
             }
         } else if recordItem?.mediaType == .IMAGE {
 //            if (recordItem?.materialDuraion ?? 0) > progress {
-            progressView.setContentOffset(CGPoint(x: progress * thumbImageWidth / 2.0, y: 0), animated: true)
+            progressView.setContentOffset(CGPoint(x: (progress < 1 ? progress * 100 : progress) * thumbImageWidth / 2.0, y: 0), animated: true)
+            appendThumb(progress: progress)
 //            }
         }
     }