|
|
@ -657,9 +657,21 @@ watch( |
|
|
|
audioStore.isPaused = false; |
|
|
|
console.log(`${audioInfo.name}音频开始播放`); |
|
|
|
}, |
|
|
|
onpause: () => { |
|
|
|
audioStore.isPlaying = false; |
|
|
|
audioStore.isPaused = true; |
|
|
|
audioStore.playbackPosition = audio.seek() || 0; |
|
|
|
console.log(`${audioInfo.name}音频已暂停,位置:`, audioStore.playbackPosition); |
|
|
|
}, |
|
|
|
onresume: () => { |
|
|
|
audioStore.isPlaying = true; |
|
|
|
audioStore.isPaused = false; |
|
|
|
console.log(`${audioInfo.name}音频继续播放`); |
|
|
|
}, |
|
|
|
onend: () => { |
|
|
|
audioStore.isPlaying = false; |
|
|
|
audioStore.isPaused = false; |
|
|
|
audioStore.playbackPosition = 0; |
|
|
|
isPlayingAudio.value = false; |
|
|
|
console.log(`${audioInfo.name}音频播放完成`); |
|
|
|
// 播放下一个音频 |
|
|
@ -667,6 +679,13 @@ watch( |
|
|
|
playNextAudio(); |
|
|
|
}, 100); |
|
|
|
}, |
|
|
|
onstop: () => { |
|
|
|
audioStore.isPlaying = false; |
|
|
|
audioStore.isPaused = false; |
|
|
|
audioStore.playbackPosition = 0; |
|
|
|
isPlayingAudio.value = false; |
|
|
|
console.log(`${audioInfo.name}音频已停止`); |
|
|
|
}, |
|
|
|
onloaderror: (id, err) => { |
|
|
|
console.error(`${audioInfo.name}音频播放失败:`, err); |
|
|
|
isPlayingAudio.value = false; |
|
|
@ -677,6 +696,8 @@ watch( |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// 设置当前音频URL到store |
|
|
|
audioStore.setCurrentAudioUrl(audioInfo.url); |
|
|
|
audioStore.nowSound = audio; |
|
|
|
audioStore.setAudioInstance(audio); |
|
|
|
audio.play(); |
|
|
@ -694,6 +715,37 @@ watch( |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
// 重写audioStore的togglePlayPause方法以支持队列播放控制 |
|
|
|
const originalTogglePlayPause = audioStore.togglePlayPause; |
|
|
|
audioStore.togglePlayPause = () => { |
|
|
|
console.log('主页音频控制按钮被点击'); |
|
|
|
console.log('当前音频状态 - isPlaying:', audioStore.isPlaying, 'isPaused:', audioStore.isPaused); |
|
|
|
console.log('当前音频实例:', audioStore.soundInstance); |
|
|
|
|
|
|
|
if (audioStore.soundInstance) { |
|
|
|
if (audioStore.isPlaying) { |
|
|
|
// 暂停当前音频 |
|
|
|
console.log('暂停当前音频'); |
|
|
|
audioStore.soundInstance.pause(); |
|
|
|
} else if (audioStore.isPaused && audioStore.playbackPosition > 0) { |
|
|
|
// 从暂停位置继续播放 |
|
|
|
console.log('从暂停位置继续播放音频,位置:', audioStore.playbackPosition); |
|
|
|
audioStore.soundInstance.seek(audioStore.playbackPosition); |
|
|
|
audioStore.soundInstance.play(); |
|
|
|
} else { |
|
|
|
// 重新开始播放 |
|
|
|
console.log('重新开始播放音频'); |
|
|
|
audioStore.soundInstance.play(); |
|
|
|
} |
|
|
|
} else { |
|
|
|
console.log('没有音频实例,尝试播放队列中的音频'); |
|
|
|
// 没有音频实例时,尝试播放队列中的音频 |
|
|
|
if (!isPlayingAudio.value && audioQueue.value.length > 0) { |
|
|
|
playNextAudio(); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
// 预加载音频函数 |
|
|
|
const preloadAudio = (url, apiKey) => { |
|
|
|
if (!url || !audioStore.isVoiceEnabled) { |
|
|
|