Skip to content

Commit 6f1909a

Browse files
committed
🐞 fix: 修复刷新后第一次播放出现的无法播放问题
1 parent c5d71cf commit 6f1909a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/renderer/store/modules/player.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ export const usePlayerStore = defineStore('player', () => {
560560
const setPlay = async (song: SongResult) => {
561561
try {
562562
// 如果是当前正在播放的音乐,则切换播放/暂停状态
563-
if (playMusic.value.id === song.id && playMusic.value.playMusicUrl === song.playMusicUrl) {
563+
if (playMusic.value.id === song.id && playMusic.value.playMusicUrl === song.playMusicUrl && !song.isFirstPlay) {
564564
if (play.value) {
565565
setPlayMusic(false);
566566
audioService.getCurrentSound()?.pause();
@@ -570,6 +570,10 @@ export const usePlayerStore = defineStore('player', () => {
570570
}
571571
return;
572572
}
573+
574+
if(song.isFirstPlay) {
575+
song.isFirstPlay = false;
576+
}
573577
// 直接调用 handlePlayMusic,它会处理索引更新和播放逻辑
574578
const success = await handlePlayMusic(song);
575579

@@ -1095,7 +1099,7 @@ export const usePlayerStore = defineStore('player', () => {
10951099
savedPlayMusic.playMusicUrl = undefined;
10961100
}
10971101

1098-
await handlePlayMusic({ ...savedPlayMusic, playMusicUrl: undefined }, isPlaying);
1102+
await handlePlayMusic({ ...savedPlayMusic, isFirstPlay: true, playMusicUrl: undefined }, isPlaying);
10991103

11001104
if (savedProgress) {
11011105
try {

src/renderer/type/music.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export interface SongResult {
4545
// 时长
4646
duration?: number;
4747
dt?: number;
48+
isFirstPlay?: boolean;
4849
}
4950

5051
export interface Song {

0 commit comments

Comments
 (0)