1. 播放器歌词效果

This commit is contained in:
李琦
2026-08-01 18:13:02 +08:00
parent 33027cf61e
commit b4dc67fda1
2 changed files with 169 additions and 42 deletions

View File

@@ -84,6 +84,28 @@ export function useAudio() {
}
}
const currentIndex = computed(() => tracks.value.findIndex((t) => t.url === activeUrl.value))
const playAt = (index) => {
const list = tracks.value
if (!list.length) return
const i = ((index % list.length) + list.length) % list.length
const url = list[i]?.url
if (!url) return
if (isPlaying.value) playUrl(url)
else setActive(url)
}
const prev = () => {
const idx = currentIndex.value
playAt(idx < 0 ? 0 : idx - 1)
}
const next = () => {
const idx = currentIndex.value
playAt(idx < 0 ? 0 : idx + 1)
}
const play = () => playUrl(activeUrl.value)
const attemptAutoplay = async () => {
@@ -154,8 +176,11 @@ export function useAudio() {
currentTime,
duration,
volume,
currentIndex,
setTracks,
setActive,
prev,
next,
play,
pause,
toggle,