Selaa lähdekoodia

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

# Conflicts:
#	BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift
合并代码
jsonwang 3 vuotta sitten
vanhempi
commit
2c4e6d89ea

+ 29 - 31
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -67,6 +67,8 @@ public class BFRecordScreenController: BFBaseViewController {
     var isNormalPlaying = false { // 是否正在播放
         didSet {
             playBtn.isSelected = isNormalPlaying
+            withDrawBtn.isHidden = isNormalPlaying
+
         }
     }
 
@@ -88,17 +90,17 @@ public class BFRecordScreenController: BFBaseViewController {
     // MARK: 行为参数
 
     var movieIsProcessing = false
-    
+
     // 行为记录,方便撤销
     var events = [WithDrawModel]() {
         didSet {
             withDrawBtn.isEnabled = (events.count != 0)
         }
     }
-    
+
     // 是否在拖动进度条
     var isDragingProgressSlder: Bool = false
-    
+
     var isStopAtRecordRange = -1
 
     // 保存识别出来的字幕信息,用于回放,和合成使用
@@ -126,11 +128,13 @@ public class BFRecordScreenController: BFBaseViewController {
     var avplayerTimeObserver: NSKeyValueObservation?
 
     var indirectionView: BFIndirectionProgressView?
-
+    
     //字幕识别 SDK 初始化参数
     var NeoNuiToken:String?
     var NeoNuiAppid:String?
      
+
+
     lazy var progreddL: UILabel = {
         let l = UILabel()
         l.textAlignment = .center
@@ -405,11 +409,12 @@ public class BFRecordScreenController: BFBaseViewController {
             BFLog(message: "nls appkey is \(appkey), token is \(token)")
             self?.NeoNuiAppid = appkey
             self?.NeoNuiToken = token
-        
+
         }
-        
         //录音字幕识别初始化相关
+
         recorderManager = BFVoiceRecordManager()
+
         // 录音进度
         recorderManager?.recorderProgrossHandle = { [weak self] progress in
             BFLog(1, message: "curr:录音进度--\(progress) \(self?.recordStartTime ?? 0) \(self?.isRecording ?? false)")
@@ -504,7 +509,7 @@ public class BFRecordScreenController: BFBaseViewController {
                     // 矫正进度
                     self?.resetCurrentProgress()
                     self?.deleteRecordBtn.isHidden = true
-                    self?.recordBtn.isHidden = false
+                    self?.recordBtn.isHidden = self?.isEndPlay ?? false
                 }
                 sself.currentPlayRecordIndex = -3 // 刚录音完,不需要播放录音
                 // 重置录制开始时间
@@ -892,6 +897,7 @@ public class BFRecordScreenController: BFBaseViewController {
         recorderManager?.startRecord()
         //开始字幕识别
         recorderManager?.audioRecorder?.startNeoNui((NeoNuiToken ?? ""), appid: (NeoNuiAppid ?? ""))
+
         if recordStartTime <= 0 {
             recordStartTime = currentAssetProgress.seconds
         }
@@ -996,15 +1002,15 @@ public class BFRecordScreenController: BFBaseViewController {
                 if itemModels[currItemModelIndex].mediaType == .IMAGE {
                     itemModels[currItemModelIndex].materialDuraion = itemModels[currItemModelIndex].voiceStickers.last?.endTime ?? 0
                 }
-                
+
             } else {}
             events.removeLast()
 
             let dur = itemModels[currItemModelIndex].materialDuraion
             if dur > 0 {
-                changeProgress(progress: Float(jumpTime / dur))
+                changeProgress(isBack: true, progress: itemModels[currItemModelIndex].mediaType == .IMAGE ? Float(jumpTime) : Float(jumpTime / dur))
             } else {
-                changeProgress(progress: Float(0))
+                changeProgress(isBack: true, progress: Float(0))
             }
             isDragingProgressSlder = false
             currentPlayRecordIndex = -1
@@ -1017,14 +1023,13 @@ public class BFRecordScreenController: BFBaseViewController {
                 changeWithDrawBtnLayout(false)
             }
             searchStopAtRecordRange()
-            
             let itemModel = itemModels[currItemModelIndex]
-            if itemModel.mediaType == .IMAGE{
+            // 如果是图片需重置播放按钮
+            if itemModel.mediaType == .IMAGE {
+                // 重置进度条
                 indirectionView?.resetAllSubViews(items: itemModels[currItemModelIndex].voiceStickers, percenWidth: progressThumV.thumbImageWidth / 2.0, totalDuration: itemModels[currItemModelIndex].materialDuraion)
-            }else {
-                
+                (collectionView.cellForItem(at: IndexPath(item: currItemModelIndex, section: 0)) as? BFImageCoverViewCell)?.playBtn.isSelected = itemModels[currItemModelIndex].voiceStickers.count <= 0
             }
-
         }
     }
 
@@ -1068,6 +1073,7 @@ public class BFRecordScreenController: BFBaseViewController {
         BFLog(1, message: "isDragingProgressSlder : \(isDragingProgressSlder)")
         searchStopAtRecordRange(needAdsorb: true)
         changeWithDrawBtnLayout(false)
+        isEndPlay = (progress == 1)
     }
 
     // 是否吸附在录音首尾处
@@ -1309,7 +1315,7 @@ public class BFRecordScreenController: BFBaseViewController {
         subtitleBtn.isHidden = false
         soundSettingBtn.isHidden = false
         withDrawBtn.isHidden = false
-        recordBtn.isHidden = false
+        recordBtn.isHidden = isEndPlay
         //        movie?.cancelProcessing()
         assetPlayer?.pause()
         recordPlayer?.pause()
@@ -1406,16 +1412,10 @@ public class BFRecordScreenController: BFBaseViewController {
 
         NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: assetPlayer?.currentItem, queue: .main) { [weak self] notify in
             BFLog(1, message: "AVPlayerItemDidPlayToEndTime = \(notify)")
-//            if (self?.currItemModelIndex ?? 0) < ((self?.itemModels.count ?? 0) - 1) {
-//                self?.collectionView.setContentOffset(CGPoint(x: CGFloat((self?.currItemModelIndex ?? 0) + 1) * (self?.collectionView.frame.width ?? 0), y: 0), animated: true)
-//            } else {
-//            }
+
             self?.isNormalPlaying = false
-            //            self?.assetPlayer?.seek(to: CMTime.zero)
-            //            self?.progressThumV.progress = 0
             self?.isEndPlay = true
-            //            self?.currentPlayRecordIndex = -1
-            self?.recordBtn.isHidden = true
+            
             if self?.isRecording ?? false {
                 self?.endRecord()
                 cShowHUB(superView: nil, msg: "此视频已录制到头了哦")
@@ -1478,7 +1478,7 @@ public class BFRecordScreenController: BFBaseViewController {
     }
 
     // 通过缩略图进度条控制播放进度
-    func changeProgress(progress: Float) {
+    func changeProgress(isBack: Bool = false, progress: Float) {
         var newProgress = progress
         if progress.isNaN || progress.isInfinite {
             newProgress = 0
@@ -1493,13 +1493,11 @@ public class BFRecordScreenController: BFBaseViewController {
                 }
             }
         } else {
-            if itemModels[currItemModelIndex].materialDuraion >= 0 {
-                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 = \(newProgress),currentAssetProgress = \(currentAssetProgress.seconds),materialDuraion = \(itemModels[currItemModelIndex].materialDuraion)")
+            currentAssetProgress = isBack ? CMTime(value: CMTimeValue(progress * 1000), timescale: 1000) : CMTime(value: CMTimeValue(progress * 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)")
         }
     }
 

+ 9 - 24
BFRecordScreenKit/Classes/RecordScreen/View/BFVideoThumbProgressView.swift

@@ -251,55 +251,40 @@ 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)
         if recordItem?.mediaType == .VIDEO {
             if isDrag {
-                let dur = scrollView.contentOffset.x / (scrollView.contentSize.width - width)
-                dragScrollProgressHandle?(false, Float(dur))
+                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)
                 }
-                let dur = scrollView.contentOffset.x / (CGFloat(recordItem?.materialDuraion ?? 0) * thumbImageWidth / 2.0)
-                dragScrollProgressHandle?(false, Float(dur))
+                dragScrollProgressHandle?(false, totalW > 0 ? Float((scrollView.contentOffset.x / totalW)) : 0)
             }
         }
     }
 
     func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
         isDrag = true
-        var dur: CGFloat = 0
-        if recordItem?.mediaType == .VIDEO {
-            dur = scrollView.contentOffset.x / (scrollView.contentSize.width - width)
-        } else {
-            dur = scrollView.contentOffset.x / (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, Float(dur))
+        dragScrollProgressHandle?(true, totalW > 0 ? Float((scrollView.contentOffset.x / totalW)) : 0)
     }
 
     func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
         if !decelerate {
-            var dur: CGFloat = 0
-            if recordItem?.mediaType == .VIDEO {
-                dur = scrollView.contentOffset.x / (scrollView.contentSize.width - width)
-            } else {
-                dur = scrollView.contentOffset.x / (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?(Float(dur))
+            dragEndHandle?(totalW > 0 ? Float((scrollView.contentOffset.x / totalW)) : 0)
         }
     }
 
     func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
         var dur: CGFloat = 0
-        if recordItem?.mediaType == .VIDEO {
-            dur = scrollView.contentOffset.x / (scrollView.contentSize.width - width)
-        } else {
-            dur = scrollView.contentOffset.x / (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?(Float(dur))
+        dragEndHandle?(totalW > 0 ? Float((scrollView.contentOffset.x / totalW)) : 0)
     }
 }