ソースを参照

修改古诗中视频的bug

丸子 1 週間 前
コミット
2deef1abb1
1 ファイル変更30 行追加12 行削除
  1. 30 12
      src/views/AIPage/aiGenerate/DialogContent.vue

+ 30 - 12
src/views/AIPage/aiGenerate/DialogContent.vue

@@ -74,6 +74,7 @@
           <video
             :src="currentDialogue.videoUrl"
             class="dialogue-video"
+            ref="dialogueVideoRef"
             controls
             autoplay
             @ended="handleVideoEnded"
@@ -218,6 +219,8 @@ const backgroundAudio = ref(null)
 const dialogueAudio = ref(null)
 // 背景视频
 const backgroundVideoRef = ref(null)
+// 对话视频
+const dialogueVideoRef = ref(null)
 // 遮罩层显示状态
 const showMask = ref(true)
 // 是否开始播放
@@ -382,7 +385,7 @@ const playDialogueAudio = (isAutoPlay = false) => {
   }
 
   // 播放当前对话的语音
-  if (currentDialogue.value?.voiceoverUrl) {
+  if (currentDialogue.value?.voiceoverUrl && currentDialogue.value?.type !== 'video') {
     const audio = new Audio(currentDialogue.value.voiceoverUrl)
     dialogueAudio.value = audio
 
@@ -439,7 +442,7 @@ const playDialogueAudio = (isAutoPlay = false) => {
         }, 2000)
       }
     })
-  } else {
+  } else if (currentDialogue.value?.type !== 'video') {
     // 检查是否是最后一个对话
     if (isAtLastDialogue()) {
       // 如果是用户输入类型,不立即触发dialogueEnded,等待AI回答完成
@@ -470,8 +473,15 @@ const togglePlay = () => {
     // 播放背景音
     playBackgroundAudio()
     if(!getIsPlaying() && !conversationInProgress.value){
-      // 开始播放序列
-      playSequence()
+      if(currentDialogue.value?.type === 'video'){
+        // 视频类型对话,播放视频
+        if (dialogueVideoRef.value) {
+          dialogueVideoRef.value.play().catch(e => console.error('对话视频播放失败:', e))
+        }
+      } else {
+        // 开始播放序列
+        playSequence()
+      }
     }
   } else {
     // 暂停所有音频
@@ -483,15 +493,17 @@ const togglePlay = () => {
 const handleVideoEnded = () => {
   // 视频播放完毕后,继续播放下一条对话
   if (isPlaying.value) {
-    if (!playNext(true)) {
-      // 播放完毕,检查是否是最后一个对话
-      if (isAtLastDialogue()) {
-        console.log('视频序列:已到达最后一个对话,触发 dialogueEnded 事件');
-        emit('dialogueEnded', props.isLastCourse);
+    setTimeout(() => {
+      if (!playNext(true)) {
+        // 播放完毕,检查是否是最后一个对话
+        if (isAtLastDialogue()) {
+          console.log('视频序列:已到达最后一个对话,触发 dialogueEnded 事件');
+          emit('dialogueEnded', props.isLastCourse);
+        }
+        isPlaying.value = false
+        stopAllAudio()
       }
-      isPlaying.value = false
-      stopAllAudio()
-    }
+    }, 1500)
   }
 }
 
@@ -502,6 +514,12 @@ const playSequence = () => {
   // 如果当前是用户输入卡片,暂停播放等待用户输入
   if (currentDialogue.value?.type === 'user') return
 
+  // 检查当前对话是否为视频类型
+  if (currentDialogue.value?.type === 'video') {
+    // 视频类型对话,不自动播放下一条,等待视频结束
+    return
+  }
+
   // 检查当前对话是否为诗词类型
   if (currentDialogue.value?.type === 'poem') {
     // 显示诗词并替换内容为最新的诗词