🐞 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

View File

@@ -560,7 +560,7 @@ export const usePlayerStore = defineStore('player', () => {
const setPlay = async (song: SongResult) => {
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) {
setPlayMusic(false);
audioService.getCurrentSound()?.pause();
@@ -570,6 +570,10 @@ export const usePlayerStore = defineStore('player', () => {
}
return;
}
if(song.isFirstPlay) {
song.isFirstPlay = false;
}
// 直接调用 handlePlayMusic它会处理索引更新和播放逻辑
const success = await handlePlayMusic(song);
@@ -1095,7 +1099,7 @@ export const usePlayerStore = defineStore('player', () => {
savedPlayMusic.playMusicUrl = undefined;
}
await handlePlayMusic({ ...savedPlayMusic, playMusicUrl: undefined }, isPlaying);
await handlePlayMusic({ ...savedPlayMusic, isFirstPlay: true, playMusicUrl: undefined }, isPlaying);
if (savedProgress) {
try {

View File

@@ -45,6 +45,7 @@ export interface SongResult {
// 时长
duration?: number;
dt?: number;
isFirstPlay?: boolean;
}
export interface Song {