Browse Source

Merge branch 'dev' of https://git.yishihui.com/iOS/BFRecordScreenKit into dev
合并代码

jsonwang 3 years ago
parent
commit
d4adfde157

+ 1 - 1
BFRecordScreenKit/Classes/BFVoiceRecordManager.swift

@@ -176,7 +176,7 @@ extension BFVoiceRecordManager: BFRecorderManagerDelegate {
         NeoNuiDebugHandle?(msg,isShow)
     }
     public func audioQueueRecoderDebugHandle(_ msg: String, isShow: Bool) {
-        BFLog(2, message: "audioQueueRecoderDebugHandle :\(msg)")
+//        BFLog(2, message: "audioQueueRecoderDebugHandle :\(msg)")
         AudioQueueRecoderDebugHandle?(msg,isShow)
     }
   

+ 25 - 23
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenCameraManager.swift

@@ -88,7 +88,7 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
 
             // 拖动的跳跃,不要修改时间点
             if wself.dele?.isNormalPlaying ?? false {
-                wself.currentAssetProgress = CMTime(seconds: (currTime + wself.currPlayTime).seconds, preferredTimescale: 1000)
+//                wself.currentAssetProgress = CMTime(seconds: (currTime + wself.currPlayTime).seconds, preferredTimescale: 1000)
 
                 BFLog(message: "当前播放器状态: \(wself.avplayer.timeControlStatus.rawValue) \(wself.currentAssetProgress.seconds)")
 
@@ -453,8 +453,8 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
             locationTo(time: currentAssetProgress)
             avplayer.replaceCurrentItem(with: nil)
         }
-
-        prepareToPlayNext()
+        
+        startTimer(isPlay: true)
     }
 
     func playRecordVoice(needPlay: Bool = true) {
@@ -479,6 +479,7 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
 
         if let mod = useVoiceStickers.first(where: { m in
             CMTimeCompare(m.startCMTime, currentAssetProgress) <= 0 && CMTimeCompare(m.endCMTime, currentAssetProgress) > 0
+
         }) {
             BFLog(message: "找到音频开始时间:\(mod.startCMTime.seconds)结束 \(mod.endCMTime.seconds) currentAssetProgress is \(currentAssetProgress.seconds)")
 
@@ -509,28 +510,37 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
     }
 
     func findNextModel() {
-        if let mod = recordItem?.videoStickers.sorted(by: { m1, m2 in
-            m1.timelineCMIn.seconds < m2.timelineCMIn.seconds
-        }).first(where: { mod in
+        if let mod = recordItem?.videoStickers.first(where: { mod in
             CMTimeCompare(mod.timelineCMIn, currentAssetProgress + CMTime(seconds: 0.6, preferredTimescale: 1000)) <= 0 && CMTimeCompare((currentAssetProgress + CMTime(seconds: 0.6, preferredTimescale: 1000)), mod.timelineCMOut) < 0
         }) {
             currPlayTime = mod.timelineCMIn
             currentAssetProgress = currPlayTime
+            BFLog(1, message: "视频查找下一个:\(currentAssetProgress.seconds)")
         }
     }
 
     func prepareToPlayNext(needPlay: Bool = true) {
-        if let mod = recordItem?.videoStickers.sorted(by: { m1, m2 in
-            m1.timelineCMIn.seconds < m2.timelineCMIn.seconds
-        }).first(where: { mode in
-            CMTimeCompare(mode.timelineCMIn, currentAssetProgress + CMTime(seconds: 0.33, preferredTimescale: 1000)) <= 0 && CMTimeCompare((currentAssetProgress + CMTime(seconds: 0.33, preferredTimescale: 1000)), mode.timelineCMOut) < 0
+        
+        if let mod = recordItem?.videoStickers.first(where: { mode in
+            CMTimeCompare(mode.timelineCMIn, currentAssetProgress) <= 0 && CMTimeCompare(currentAssetProgress, mode.timelineCMOut) < 0
         }) {
+            // true 代表需要换源
+            let su = (assetPlayer?.currentItem?.asset as? AVURLAsset)?.url.lastPathComponent != (mod.locationPath as NSString?)?.lastPathComponent
+            
+            if !su {
+                if avplayer.timeControlStatus == .paused {
+                    avplayer.play()
+                }
+                return
+            }
+            
             currPlayTime = mod.timelineCMIn
             locationTo(time: currentAssetProgress)
             avplayerReplaceItem(newItem: AVPlayerItem(url: URL(fileURLWithPath: mod.locationPath)))
-
+            BFLog(1, message: "当前:\(currentAssetProgress.seconds), mod:\(mod.timelineCMIn.seconds) ~ \(mod.timelineCMOut.seconds)")
             let tt = currentAssetProgress - currPlayTime
             BFLog(1, message: "asset - tt: \(tt.seconds), curr:\(currentAssetProgress.seconds)")
+            
             if CMTimeCompare(tt, (avplayer.currentItem?.duration ?? .zero)) == 0 {
                 if needPlay {
                     avplayer.play()
@@ -543,21 +553,10 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
                     }
                 })
             }
-            dispatchWorkItemIsCancel = false
-            playRecordVoice(needPlay: needPlay)
-            if (recordItem?.voiceChangeStickers.count ?? 0) > 0 {
-                for model in recordItem!.voiceChangeStickers {
-                    BFLog(message: "音频文件时间范围:\(model.startCMTime.seconds) 到 \(model.endCMTime.seconds) file path \(model.wavFilePath ?? "")")
-                }
-            }
-
         } else {
             locationTo(time: currentAssetProgress)
             playerCoverIV.isHidden = true
-        }
-//        playerCoverIV.isHidden = (CMTimeCompare(currentAssetProgress, recordItem?.materialDuraion ?? .zero) >= 0)
-        if !playerCoverIV.isHidden {
-            BFLog(1, message: "stor")
+            BFLog(1, message: "prepareToPlayNext: 没找到 \(currentAssetProgress.seconds)")
         }
     }
 
@@ -701,6 +700,8 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
         currentAssetProgress = min(currTime, (recordItem?.materialDuraion ?? .zero))
         dele?.progressThumV.progress = currentAssetProgress
         dele?.updateSubtitle(time: currentAssetProgress)
+//        locationTo(time: wself.currentAssetProgress)
+        progreddL?.text = CMTimeGetSeconds(currentAssetProgress).formatDurationToHMS()
 
         if currTime.seconds >= (recordItem?.materialDuraion.seconds ?? 0) {
             dele?.pause()
@@ -709,6 +710,7 @@ class BFRecordScreenCameraManager: BFRecordScreenBaseManager {
         }
 
         checkCurrentPlayStatus()
+        prepareToPlayNext()
     }
 
     func timerForRecord(currTime _: CMTime) {

+ 1 - 0
BFRecordScreenKit/Classes/RecordScreen/View/ProgressView/BFCameraProgressView.swift

@@ -73,6 +73,7 @@ class BFCameraProgressView: BFProgressBaseView {
             }){
                 if ind == 0 {
                     iv.frame = CGRect(x: cScreenWidth / 2.0, y: 0, width: 0, height: 50)
+                    wself.newRecordLine = false
                 }else{
                     if wself.imageViews.count > ind - 1 {
                         let lastiv = wself.imageViews[ind - 1]