🐞 fix: 修复刷新后第一次播放出现的无法播放问题

This commit is contained in:
alger
2025-06-07 22:10:55 +08:00
parent c5d71cf53c
commit 6f1909a028
2 changed files with 7 additions and 2 deletions
+6 -2
View File
@@ -560,7 +560,7 @@ export const usePlayerStore = defineStore('player', () => {
const setPlay = async (song: SongResult) => { const setPlay = async (song: SongResult) => {
try { try {
// 如果是当前正在播放的音乐,则切换播放/暂停状态 // 如果是当前正在播放的音乐,则切换播放/暂停状态
if (playMusic.value.id === song.id && playMusic.value.playMusicUrl === song.playMusicUrl) { if (playMusic.value.id === song.id && playMusic.value.playMusicUrl === song.playMusicUrl && !song.isFirstPlay) {
if (play.value) { if (play.value) {
setPlayMusic(false); setPlayMusic(false);
audioService.getCurrentSound()?.pause(); audioService.getCurrentSound()?.pause();
@@ -570,6 +570,10 @@ export const usePlayerStore = defineStore('player', () => {
} }
return; return;
} }
if(song.isFirstPlay) {
song.isFirstPlay = false;
}
// 直接调用 handlePlayMusic,它会处理索引更新和播放逻辑 // 直接调用 handlePlayMusic,它会处理索引更新和播放逻辑
const success = await handlePlayMusic(song); const success = await handlePlayMusic(song);
@@ -1095,7 +1099,7 @@ export const usePlayerStore = defineStore('player', () => {
savedPlayMusic.playMusicUrl = undefined; savedPlayMusic.playMusicUrl = undefined;
} }
await handlePlayMusic({ ...savedPlayMusic, playMusicUrl: undefined }, isPlaying); await handlePlayMusic({ ...savedPlayMusic, isFirstPlay: true, playMusicUrl: undefined }, isPlaying);
if (savedProgress) { if (savedProgress) {
try { try {
+1
View File
@@ -45,6 +45,7 @@ export interface SongResult {
// 时长 // 时长
duration?: number; duration?: number;
dt?: number; dt?: number;
isFirstPlay?: boolean;
} }
export interface Song { export interface Song {