fix(播放器): 修复播放队列和缓冲状态的处理逻辑

修复播放队列在到达底部时的暂停逻辑,并确保缓冲状态在播放时正确更新。调整了音频元素的自动播放逻辑,使其与播放状态同步。
This commit is contained in:
Astrian Zheng 2025-05-25 08:31:25 +10:00
parent a51ddcc023
commit 9d9c3a3ed5
Signed by: Astrian
SSH Key Fingerprint: SHA256:rVnhx3DAKjujCwWE13aDl7uV6+9U1MvydLkNRXJrBiA
2 changed files with 8 additions and 3 deletions

View File

@ -44,8 +44,10 @@ function setMetadata() {
function playNext() {
if (playQueueStore.currentIndex === playQueueStore.list.length - 1) {
console.log("at the bottom, pause")
playQueueStore.currentIndex = 0
player.value?.pause()
playQueueStore.isPlaying = false
} else {
playQueueStore.currentIndex++
player.value?.play()
@ -66,9 +68,11 @@ function playPrevious() {
<div>
<audio
:src="playQueueStore.list[playQueueStore.currentIndex] ? playQueueStore.list[playQueueStore.currentIndex].song.sourceUrl : ''"
ref="playerRef" autoplay v-if="playQueueStore.list.length !== 0" @ended="playNext"
@pause="playQueueStore.isPlaying = false" @play="playQueueStore.isPlaying = true"
@playing="playQueueStore.isBuffering = false" @waiting="playQueueStore.isBuffering = true">
ref="playerRef" :autoplay="playQueueStore.isPlaying" v-if="playQueueStore.list.length !== 0" @ended="playNext"
@pause="playQueueStore.isPlaying = false" @play="playQueueStore.isPlaying = true" @playing="() => {
playQueueStore.isBuffering = false
setMetadata()
}" @waiting="playQueueStore.isBuffering = true">
</audio>
<div

View File

@ -48,6 +48,7 @@ function playTheAlbum() {
playQueue.list = newPlayQueue
playQueue.currentIndex = 0
playQueue.isPlaying = true
playQueue.isBuffering = true
}
</script>