mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-05-17 10:27:30 +08:00
fix(player): 私人 FM 模式下点击下一首按钮可正常切歌
FM 播放列表只保留 1 首,原 _nextPlay 走到"顺序模式 + 最后一首" 分支只弹"列表已播完"提示,仅 audioService end 事件中拉取下一首 FM 的逻辑生效,导致用户手动点击下一首无效(issue #666)。 抽出 _nextFmPlay,_nextPlay 入口检测 isFmPlaying 直接路由到 FM 分支;MusicHook end 事件去掉重复的 FM 处理,统一走 nextPlayOnEnd。
This commit is contained in:
@@ -535,43 +535,12 @@ const setupAudioListeners = () => {
|
|||||||
if (getPlayerStore().playMode === 1) {
|
if (getPlayerStore().playMode === 1) {
|
||||||
// 单曲循环模式
|
// 单曲循环模式
|
||||||
replayMusic();
|
replayMusic();
|
||||||
} else if (getPlayerStore().isFmPlaying) {
|
return;
|
||||||
// 私人FM模式:自动获取下一首
|
|
||||||
try {
|
|
||||||
const { getPersonalFM } = await import('@/api/home');
|
|
||||||
const res = await getPersonalFM();
|
|
||||||
const songs = res.data?.data;
|
|
||||||
if (Array.isArray(songs) && songs.length > 0) {
|
|
||||||
const song = songs[0];
|
|
||||||
const fmSong = {
|
|
||||||
id: song.id,
|
|
||||||
name: song.name,
|
|
||||||
picUrl: song.al?.picUrl || song.album?.picUrl,
|
|
||||||
ar: song.artists || song.ar,
|
|
||||||
al: song.al || song.album,
|
|
||||||
source: 'netease' as const,
|
|
||||||
song,
|
|
||||||
...song,
|
|
||||||
playLoading: false
|
|
||||||
} as any;
|
|
||||||
const { usePlaylistStore } = await import('@/store/modules/playlist');
|
|
||||||
const playlistStore = usePlaylistStore();
|
|
||||||
playlistStore.setPlayList([fmSong], false, false);
|
|
||||||
getPlayerStore().isFmPlaying = true; // setPlayList 会清除,需重设
|
|
||||||
const { playTrack } = await import('@/services/playbackController');
|
|
||||||
await playTrack(fmSong, true);
|
|
||||||
} else {
|
|
||||||
getPlayerStore().setIsPlay(false);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('FM自动播放下一首失败:', error);
|
|
||||||
getPlayerStore().setIsPlay(false);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 顺序播放、列表循环、随机播放模式:歌曲自然结束
|
|
||||||
const { usePlaylistStore } = await import('@/store/modules/playlist');
|
|
||||||
usePlaylistStore().nextPlayOnEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 其他模式(FM/顺序/列表循环/随机):交给 playlist store 路由
|
||||||
|
const { usePlaylistStore } = await import('@/store/modules/playlist');
|
||||||
|
usePlaylistStore().nextPlayOnEnd();
|
||||||
});
|
});
|
||||||
|
|
||||||
audioService.on('previoustrack', () => {
|
audioService.on('previoustrack', () => {
|
||||||
|
|||||||
@@ -424,8 +424,55 @@ export const usePlaylistStore = defineStore(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 私人FM:拉取下一首并播放(FM 列表始终只保留当前一首)
|
||||||
|
*/
|
||||||
|
const _nextFmPlay = async () => {
|
||||||
|
const playerCore = usePlayerCoreStore();
|
||||||
|
try {
|
||||||
|
const { getPersonalFM } = await import('@/api/home');
|
||||||
|
const res = await getPersonalFM();
|
||||||
|
const songs = res.data?.data;
|
||||||
|
if (!Array.isArray(songs) || songs.length === 0) {
|
||||||
|
playerCore.setIsPlay(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const song = songs[0];
|
||||||
|
const fmSong = {
|
||||||
|
id: song.id,
|
||||||
|
name: song.name,
|
||||||
|
picUrl: song.al?.picUrl || song.album?.picUrl,
|
||||||
|
ar: song.artists || song.ar,
|
||||||
|
al: song.al || song.album,
|
||||||
|
source: 'netease' as const,
|
||||||
|
song,
|
||||||
|
...song,
|
||||||
|
playLoading: false
|
||||||
|
} as any;
|
||||||
|
await setPlayList([fmSong], false, false);
|
||||||
|
playerCore.isFmPlaying = true;
|
||||||
|
const { playTrack } = await import('@/services/playbackController');
|
||||||
|
await playTrack(fmSong, true);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('FM切换下一首失败:', error);
|
||||||
|
playerCore.setIsPlay(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const _nextPlay = async (retryCount: number = 0, autoEnd: boolean = false) => {
|
const _nextPlay = async (retryCount: number = 0, autoEnd: boolean = false) => {
|
||||||
try {
|
try {
|
||||||
|
const playerCore = usePlayerCoreStore();
|
||||||
|
|
||||||
|
// 私人FM模式:忽略 playMode 与列表长度,直接拉取新的 FM 歌曲
|
||||||
|
if (playerCore.isFmPlaying) {
|
||||||
|
if (retryCount === 0) {
|
||||||
|
cancelRetryTimer();
|
||||||
|
consecutiveFailCount.value = 0;
|
||||||
|
}
|
||||||
|
await _nextFmPlay();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (playList.value.length === 0) return;
|
if (playList.value.length === 0) return;
|
||||||
|
|
||||||
// User-initiated (retryCount=0): reset state
|
// User-initiated (retryCount=0): reset state
|
||||||
@@ -434,7 +481,6 @@ export const usePlaylistStore = defineStore(
|
|||||||
consecutiveFailCount.value = 0;
|
consecutiveFailCount.value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const playerCore = usePlayerCoreStore();
|
|
||||||
const sleepTimerStore = useSleepTimerStore();
|
const sleepTimerStore = useSleepTimerStore();
|
||||||
|
|
||||||
if (consecutiveFailCount.value >= MAX_CONSECUTIVE_FAILS) {
|
if (consecutiveFailCount.value >= MAX_CONSECUTIVE_FAILS) {
|
||||||
|
|||||||
Reference in New Issue
Block a user