Преглед изворни кода

字幕显示问题修改:间断刷新字幕,精准查找显示

harry пре 3 година
родитељ
комит
a3c897f6b3

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

@@ -40,7 +40,7 @@ public class BFRecordScreenController: BFBaseViewController {
     var currItemModelIndex = 0
     public var itemModels = [BFRecordItemModel]()
     // add by ak 当前的显示的字幕位置
-    var showSubtitleIndex = 0
+    var showSubtitleIndex = -1
     //    var shouldPlayRecordIndex:Int = -1          // 当前应该播放的录音资源序号
     var currentPlayRecordIndex: Int = -1 // >= 0 :当前正在播放的录音资源序号; -3: 刚录音完,不需要播放录音; -1:初始化阶段
     public var displayLink: CADisplayLink? // 图片素材播放控制
@@ -733,7 +733,7 @@ public class BFRecordScreenController: BFBaseViewController {
             subtitleEditView.textView.becomeFirstResponder()
             subtitleEditView.setNewText(text: subtitleLabel.text ?? "", index: showSubtitleIndex)
         } else {
-            BFLog(message: "播放状态不可以编辑字幕")
+            BFLog(message: "播放状态,内容为空时不可以编辑字幕")
         }
     }
 
@@ -741,9 +741,26 @@ public class BFRecordScreenController: BFBaseViewController {
     /// - Parameter time: 当前播放的进度
     func updateSubtitle(time: CMTime) {
         BFLog(message: "currTime is \(CMTimeGetSeconds(time))")
-        if isRecording || !subtitleSettingView.subtitle.setting.subtitleIsShow {
+        if isRecording || !subtitleSettingView.subtitle.setting.subtitleIsShow || currentPlayRecordIndex == -3 {
+            // currentPlayRecordIndex == -3 代表刚录完音,不要找字幕,会因为小幅度回退seek导致上一个字幕出现
             return
         }
+        
+        if showSubtitleIndex > -1, showSubtitleIndex < itemModels[currItemModelIndex].titleStickers.count {
+            let currShowSubtitle = itemModels[currItemModelIndex].titleStickers[showSubtitleIndex]
+    
+            if CMTimeCompare(currShowSubtitle.timelineIn, time) <= 0, CMTimeCompare(currShowSubtitle.timelineOut, time) > 0{
+                // 已存在字幕
+                if subtitleLabel.text != currShowSubtitle.text{
+                    subtitleLabel.text = currShowSubtitle.text
+                    setSubtitleStyle(settingModel: subtitleSettingView.subtitle.setting)
+                }
+                return
+            }
+            showSubtitleIndex = -1
+        }
+        
+        
         var findShowSubtitle: PQEditSubTitleModel?
         for (index, subtitle) in itemModels[currItemModelIndex].titleStickers.enumerated() {
             if CMTimeCompare(subtitle.timelineIn, time) <= 0, CMTimeCompare(subtitle.timelineOut, time) > 0, subtitle.audioFilePath.count > 0 { //  audioFilePath.count 这个条件是确保这个字幕有对应录音
@@ -753,8 +770,9 @@ public class BFRecordScreenController: BFBaseViewController {
                 break
             }
         }
-        if findShowSubtitle != nil, subtitleSettingView.subtitle.setting.subtitleIsShow {
-            subtitleLabel.text = findShowSubtitle?.text ?? ""
+        
+        if findShowSubtitle != nil, subtitleLabel.text != findShowSubtitle!.text {
+            subtitleLabel.text = findShowSubtitle!.text
             setSubtitleStyle(settingModel: subtitleSettingView.subtitle.setting)
 
         } else {
@@ -1443,6 +1461,7 @@ public class BFRecordScreenController: BFBaseViewController {
                 assetPlayer?.volume = noSpeakVolume
             }
         }
+        BFLog(1, message: "volume:\(assetPlayer?.volume ?? -1)")
 
         if currentPlayRecordIndex == -3 { // 刚录音完,不需要播放
             return