浏览代码

1.图片进度可滑动区域 2.字幕点击

wenweiwei 3 年之前
父节点
当前提交
7809ba4c7c

+ 2 - 2
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -458,7 +458,7 @@ public class BFRecordScreenController: BFBaseViewController {
                 newSubtitle.taskID = (header?["task_id"] as? String) ?? ""
 
                 // 这里加300ms 是因为返回结果为了切到字,时长提前一些时间,具体时间官方没说和原音频有关系。这里我们先延后300ms 单位:毫秒。
-                if URL(fileURLWithPath: audioFilePath ?? "b").deletingPathExtension().lastPathComponent.contains(URL(fileURLWithPath: (self?.recorderManager?.voiceModel?.wavFilePath ?? "aa")).deletingPathExtension().lastPathComponent) {
+                if URL(fileURLWithPath: audioFilePath ?? "b").deletingPathExtension().lastPathComponent.contains(URL(fileURLWithPath: self?.recorderManager?.voiceModel?.wavFilePath ?? "aa").deletingPathExtension().lastPathComponent) {
                     newSubtitle.timelineIn = (self?.recorderManager?.voiceModel?.startCMTime.seconds ?? 0.0) + Float64((((payload?["begin_time"]) as? Int) ?? 0) + 300) / 1000.0
                     newSubtitle.timelineOut = (self?.recorderManager?.voiceModel?.startCMTime.seconds ?? 0.0) + Float64(((payload?["time"]) as? Int) ?? 0) / 1000.0
                 } else {
@@ -604,9 +604,9 @@ public class BFRecordScreenController: BFBaseViewController {
         //        playView = GPUImageView(frame: view.bounds)
         //        view.addSubview(playView!)
         fetchVideo()
+        view.addSubview(bottomeView)
         view.addSubview(subtitleLabel)
         view.addSubview(playBtn)
-        view.addSubview(bottomeView)
         view.addSubview(avatarView)
         //        view.addSubview(openCameraBtn)
         //        view.addSubview(drawPinBtn)

+ 41 - 23
BFRecordScreenKit/Classes/RecordScreen/View/BFVideoThumbProgressView.swift

@@ -31,11 +31,11 @@ class BFVideoThumbProgressView: UIView {
     var dragStartHandle: (() -> Void)?
     var isDrag = false
 
-    let thumbImageWidth : CGFloat = 70.0
+    let thumbImageWidth: CGFloat = 70.0
 
     let fetchThumbStrategy: BFVideoThumbProgressStrategyProtocol = BFVideoThumbProgressStrategy()
 
-    var progress: Double = 0 {  // 进度,秒为单位
+    var progress: Double = 0 { // 进度,秒为单位
         didSet {
             updateProgress(progress: progress)
         }
@@ -76,7 +76,7 @@ class BFVideoThumbProgressView: UIView {
             make.width.equalTo(3)
             make.center.height.equalToSuperview()
         }
-        
+
         progressView.contentView.addSubview(progessIndicateBackV)
         progessIndicateBackV.snp.makeConstraints { make in
             make.left.equalTo(width * 0.5)
@@ -103,11 +103,11 @@ class BFVideoThumbProgressView: UIView {
     func dealWithVideoThumb() {
         guard let videoAsset = recordItem?.videoAsset else {
             // 可能icloud资源没回来,清空原有内容
-            self.addThumbImages(images: [UIImage]())
+            addThumbImages(images: [UIImage]())
             return
         }
-        self.addThumbImages(images: recordItem!.thumbImgs)
-        if recordItem!.thumbImgs.count > 0{
+        addThumbImages(images: recordItem!.thumbImgs)
+        if recordItem!.thumbImgs.count > 0 {
             // 代表已经获取过了,不用在重新去获得
             progessIndicateBackV.snp.remakeConstraints { make in
                 make.left.equalTo(width * 0.5)
@@ -118,7 +118,7 @@ class BFVideoThumbProgressView: UIView {
             }
             return
         }
-        
+
         let date = Date()
         let dur = videoAsset.duration.seconds
         if dur > 0 {
@@ -130,24 +130,23 @@ class BFVideoThumbProgressView: UIView {
                 make.height.equalTo(6)
                 make.width.equalTo(CGFloat(count) * thumbImageWidth).priority(.high)
             }
-            
-            
-            recordItem!.splitVideoFileUrlFps(frames: count, firstImagesCount: Int(ceil(width/2.0/thumbImageWidth))) { [weak self, weak recordItem] hadGetAll, images in
+
+            recordItem!.splitVideoFileUrlFps(frames: count, firstImagesCount: Int(ceil(width / 2.0 / thumbImageWidth))) { [weak self, weak recordItem] hadGetAll, images in
                 guard let sself = self, let sitem = recordItem else {
                     return
                 }
 
-                BFLog(1, message: "获取缩略图:\(hadGetAll), \(Date().timeIntervalSince(date)), \( sitem.localPath ?? "aa")")
+                BFLog(1, message: "获取缩略图:\(hadGetAll), \(Date().timeIntervalSince(date)), \(sitem.localPath ?? "aa")")
                 sitem.thumbImgs.removeAll()
                 sitem.thumbImgs.append(contentsOf: images)
-                
+
                 // 不足数则补充足够帧数
-                while (hadGetAll && sitem.thumbImgs.count < count && images.count > 0) {
+                while hadGetAll, sitem.thumbImgs.count < count, images.count > 0 {
                     sitem.thumbImgs.append(images.last!)
                 }
                 if sitem.localPath == sself.recordItem!.localPath {
                     sself.addThumbImages(images: sitem.thumbImgs)
-                }else{
+                } else {
                     BFLog(1, message: "thumbImgs.count:\(sitem.thumbImgs.count)")
                 }
             }
@@ -193,6 +192,13 @@ class BFVideoThumbProgressView: UIView {
                         // 图片需要动态修改宽度
                         lastImg.snp.makeConstraints { make in
                             make.right.equalTo(sself.width * -0.5)
+                            make.height.equalTo(50)
+                            make.width.equalTo(sself.thumbImageWidth)
+                        }
+                        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) { [weak self] in
+                            lastImg.snp.updateConstraints { make in
+                                make.width.equalTo(self?.thumbImageWidth ?? 70)
+                            }
                         }
                     }
                 }
@@ -207,6 +213,7 @@ class BFVideoThumbProgressView: UIView {
             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)
@@ -219,8 +226,19 @@ class BFVideoThumbProgressView: UIView {
                     make.height.equalTo(50)
                     make.width.equalTo(thumbImageWidth)
                 }
+                lastiv = iv
                 thumbImgs.append(image)
             }
+            lastiv.snp.makeConstraints { make in
+                make.right.equalTo(width * -0.5)
+                make.height.equalTo(50)
+                make.width.equalTo(thumbImageWidth)
+            }
+            DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) { [weak self] in
+                lastiv.snp.updateConstraints { make in
+                    make.width.equalTo(self?.thumbImageWidth ?? 70)
+                }
+            }
         }
     }
 
@@ -248,39 +266,39 @@ class BFVideoThumbProgressView: UIView {
 
 extension BFVideoThumbProgressView: UIScrollViewDelegate {
     func scrollViewDidScroll(_ scrollView: UIScrollView) {
-        let totalW = recordItem?.mediaType == .VIDEO ? (scrollView.contentSize.width - width) :  (CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0)
+        let totalW = recordItem?.mediaType == .VIDEO ? (scrollView.contentSize.width - width) : (CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0)
         if recordItem?.mediaType == .VIDEO {
             if isDrag {
-                dragScrollProgressHandle?(false, totalW > 0 ? Float((scrollView.contentOffset.x / totalW)) : 0)
+                dragScrollProgressHandle?(false, totalW > 0 ? Float(scrollView.contentOffset.x / totalW) : 0)
             }
         } else if recordItem?.mediaType == .IMAGE {
             if isDrag {
                 if scrollView.contentOffset.x > CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0 {
                     scrollView.contentOffset = CGPoint(x: CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0, y: 0)
                 }
-                dragScrollProgressHandle?(false, totalW > 0 ? Float((scrollView.contentOffset.x / totalW)) : 0)
+                dragScrollProgressHandle?(false, totalW > 0 ? Float(scrollView.contentOffset.x / totalW) : 0)
             }
         }
     }
 
     func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
         isDrag = true
-        let totalW = recordItem?.mediaType == .VIDEO ? (scrollView.contentSize.width - width) :  (CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0)
+        let totalW = recordItem?.mediaType == .VIDEO ? (scrollView.contentSize.width - width) : (CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0)
         dragStartHandle?()
-        dragScrollProgressHandle?(true, totalW > 0 ? Float((scrollView.contentOffset.x / totalW)) : 0)
+        dragScrollProgressHandle?(true, totalW > 0 ? Float(scrollView.contentOffset.x / totalW) : 0)
     }
 
     func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
         if !decelerate {
-            let totalW = recordItem?.mediaType == .VIDEO ? (scrollView.contentSize.width - width) :  (CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0)
+            let totalW = recordItem?.mediaType == .VIDEO ? (scrollView.contentSize.width - width) : (CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0)
             isDrag = false
-            dragEndHandle?(totalW > 0 ? Float((scrollView.contentOffset.x / totalW)) : 0)
+            dragEndHandle?(totalW > 0 ? Float(scrollView.contentOffset.x / totalW) : 0)
         }
     }
 
     func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
-        let totalW = recordItem?.mediaType == .VIDEO ? (scrollView.contentSize.width - width) :  (CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0)
+        let totalW = recordItem?.mediaType == .VIDEO ? (scrollView.contentSize.width - width) : (CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0)
         isDrag = false
-        dragEndHandle?(totalW > 0 ? Float((scrollView.contentOffset.x / totalW)) : 0)
+        dragEndHandle?(totalW > 0 ? Float(scrollView.contentOffset.x / totalW) : 0)
     }
 }