Merge pull request #712 from daili115/trae/agent-m1V9o5

feat: 优化音乐播放性能,实现异步加载和即时预加载
This commit is contained in:
alger
2026-07-05 13:55:34 +08:00
4 changed files with 41 additions and 53 deletions
+7 -5
View File
@@ -107,7 +107,7 @@ export const usePlaylistStore = defineStore(
};
/**
* 智能预加载下一首歌曲
* 智能预加载下一首歌曲(立即执行,不等待)
*/
const preloadNextSongs = (currentIndex: number) => {
if (playList.value.length <= 1) return;
@@ -125,9 +125,11 @@ export const usePlaylistStore = defineStore(
nextIndex = (currentIndex + 1) % playList.value.length;
}
// 预加载下一首和下下首(最多2首)
const endIndex = Math.min(nextIndex + 2, playList.value.length);
if (nextIndex < playList.value.length) {
// 立即执行预加载
fetchSongs(nextIndex, endIndex);
// 循环模式且接近列表末尾,预加载列表开头
@@ -136,9 +138,8 @@ export const usePlaylistStore = defineStore(
nextIndex + 1 >= playList.value.length &&
playList.value.length > 2
) {
setTimeout(() => {
fetchSongs(0, 1);
}, 1000);
// 立即预加载,不等待
fetchSongs(0, 1);
}
}
};
@@ -636,7 +637,8 @@ export const usePlaylistStore = defineStore(
if (success) {
playerCore.isPlay = true;
if (songIndex !== -1) {
setTimeout(() => preloadNextSongs(playListIndex.value), 3000);
// 立即预加载,不等待
preloadNextSongs(playListIndex.value);
}
}
return success;