Browse Source

可重复播放,差音频按钮的状态样式

master^2
no99 4 days ago
parent
commit
2636c555ec
  1. 65
      src/views/AIchat.vue

65
src/views/AIchat.vue

@ -67,10 +67,25 @@ const playNextAudio = () => {
} }
if (currentPlayIndex >= audioQueue.value.length) { if (currentPlayIndex >= audioQueue.value.length) {
console.log("所有音频播放完成");
isPlayingAudio.value = false;
console.log("所有音频播放完成,重置到第一个音频");
//
currentPlayIndex = 0;
audioStore.isPlaying = false;
audioStore.isPaused = false;
audioStore.playbackPosition = 0;
//
audioStore.soundInstance = null;
audioStore.nowSound = null;
if (audioQueue.value.length > 0) {
audioStore.setCurrentAudioUrl(audioQueue.value[0]);
}
return; return;
} }
// if (currentPlayIndex >= audioQueue.value.length) {
// console.log("");
// isPlayingAudio.value = false;
// return;
// }
isCallingPlayNext = true; isCallingPlayNext = true;
const audioInfo = audioQueue.value[currentPlayIndex]; const audioInfo = audioQueue.value[currentPlayIndex];
@ -138,6 +153,11 @@ const playNextAudio = () => {
audioStore.soundInstance = null; audioStore.soundInstance = null;
// currentPlayIndex = 0; // currentPlayIndex = 0;
isCallingPlayNext = false; isCallingPlayNext = false;
// setTimeout(() => {
// isCallingPlayNext = false;
// playNextAudio();
// }, 500); // 500ms
} }
}, },
onstop: () => { onstop: () => {
@ -194,7 +214,11 @@ const addToAudioQueue = (url, name) => {
!audioStore.isPlaying && !audioStore.isPlaying &&
audioQueue.value.length === 1 audioQueue.value.length === 1
) { ) {
console.log("✅ 条件满足:没有音频在播放且这是第一个音频,立即开始播放");
console.log("✅ 条件满足:没有音频在播放且这是第一个音频,立即开始播放", {
isPlayingAudio: isPlayingAudio.value,
audioStoreIsPlaying: audioStore.isPlaying,
queueLength: audioQueue.value.length,
});
playNextAudio(); playNextAudio();
} else { } else {
console.log("⏳ 等待条件:", { console.log("⏳ 等待条件:", {
@ -231,13 +255,16 @@ const toggleVoiceForUser = (index) => {
) { ) {
return; return;
} }
// //
chatStore.messages[index].audioStatus = chatStore.messages[index].audioStatus =
!chatStore.messages[index].audioStatus; !chatStore.messages[index].audioStatus;
// //
if (chatStore.currentUserIndex != index) { if (chatStore.currentUserIndex != index) {
if (chatStore.currentUserIndex != null) { if (chatStore.currentUserIndex != null) {
if (audioStore.isPlaying) {
audioStore.togglePlayPause(); audioStore.togglePlayPause();
}
chatStore.messages[chatStore.currentUserIndex].audioStatus = false; chatStore.messages[chatStore.currentUserIndex].audioStatus = false;
} }
@ -245,6 +272,22 @@ const toggleVoiceForUser = (index) => {
audioPreloadStatus.two = { loaded: false, url: null }; audioPreloadStatus.two = { loaded: false, url: null };
audioPreloadStatus.three = { loaded: false, url: null }; audioPreloadStatus.three = { loaded: false, url: null };
audioPreloadStatus.four = { loaded: false, url: null }; audioPreloadStatus.four = { loaded: false, url: null };
if (chatStore.messages[index].audioArray[0]) {
audioPreloadStatus.one.loaded = true;
audioPreloadStatus.one.url = chatStore.messages[index].audioArray[0];
}
if (chatStore.messages[index].audioArray[1]) {
audioPreloadStatus.two.loaded = true;
audioPreloadStatus.two.url = chatStore.messages[index].audioArray[1];
}
if (chatStore.messages[index].audioArray[2]) {
audioPreloadStatus.three.loaded = true;
audioPreloadStatus.three.url = chatStore.messages[index].audioArray[2];
}
if (chatStore.messages[index].audioArray[3]) {
audioPreloadStatus.four.loaded = true;
audioPreloadStatus.four.url = chatStore.messages[index].audioArray[3];
}
chatStore.currentUserIndex = index; chatStore.currentUserIndex = index;
audioQueue.value = []; audioQueue.value = [];
isPlayingAudio.value = false; isPlayingAudio.value = false;
@ -270,7 +313,17 @@ const toggleVoiceForUser = (index) => {
console.log("1111"); console.log("1111");
audioStore.toggleVoice(); audioStore.toggleVoice();
} else { } else {
if (audioStore.currentAudioUrl || audioStore.ttsUrl) {
if (currentPlayIndex >= audioQueue.value.length) {
console.log("重新开始播放音频序列");
currentPlayIndex = 0;
isPlayingAudio.value = false;
isCallingPlayNext = false;
audioStore.soundInstance = null;
//
if (audioQueue.value.length > 0) {
playNextAudio();
}
} else if (audioStore.currentAudioUrl || audioStore.ttsUrl) {
console.log("2222"); console.log("2222");
audioStore.togglePlayPause(); audioStore.togglePlayPause();
} else { } else {
@ -540,7 +593,7 @@ const playAudioSequence = (audioUrls) => {
// togglePlayPause // togglePlayPause
const originalTogglePlayPause = audioStore.togglePlayPause; const originalTogglePlayPause = audioStore.togglePlayPause;
audioStore.togglePlayPause = () => { audioStore.togglePlayPause = () => {
console.log("音频控制按钮被点击");
console.log("音频控制按钮被点击 11111111111");
console.log("当前播放状态:", audioStore.isPlaying); console.log("当前播放状态:", audioStore.isPlaying);
console.log("当前暂停状态:", audioStore.isPaused); console.log("当前暂停状态:", audioStore.isPaused);
console.log("当前音频实例:", audioStore.soundInstance); console.log("当前音频实例:", audioStore.soundInstance);
@ -1225,7 +1278,7 @@ watch(
// audioStoretogglePlayPause // audioStoretogglePlayPause
const originalTogglePlayPause = audioStore.togglePlayPause; const originalTogglePlayPause = audioStore.togglePlayPause;
audioStore.togglePlayPause = () => { audioStore.togglePlayPause = () => {
console.log("主页音频控制按钮被点击22222");
console.log("主页音频控制按钮被点击22222222222222");
console.log( console.log(
"当前音频状态 - isPlaying:", "当前音频状态 - isPlaying:",
audioStore.isPlaying, audioStore.isPlaying,

Loading…
Cancel
Save