mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-07-08 18:37:31 +08:00
feat: 优化音乐播放逻辑
This commit is contained in:
@@ -15,6 +15,7 @@ pinia.use(({ store }) => {
|
||||
});
|
||||
|
||||
// 导出所有 store
|
||||
export * from './modules/favorite';
|
||||
export * from './modules/intelligenceMode';
|
||||
export * from './modules/localMusic';
|
||||
export * from './modules/lyric';
|
||||
@@ -22,6 +23,7 @@ export * from './modules/menu';
|
||||
export * from './modules/music';
|
||||
export * from './modules/player';
|
||||
export * from './modules/playerCore';
|
||||
export * from './modules/playHistory';
|
||||
export * from './modules/playlist';
|
||||
export * from './modules/recommend';
|
||||
export * from './modules/search';
|
||||
|
||||
@@ -405,6 +405,12 @@ export const usePlaylistStore = defineStore(
|
||||
const nowPlayListIndex = (playListIndex.value + 1) % playList.value.length;
|
||||
const nextSong = { ...playList.value[nowPlayListIndex] };
|
||||
|
||||
// 同一首歌重试时强制刷新在线 URL,避免卡在失效链接上
|
||||
if (singleTrackRetryCount > 0 && !nextSong.playMusicUrl?.startsWith('local://')) {
|
||||
nextSong.playMusicUrl = undefined;
|
||||
nextSong.expiredAt = undefined;
|
||||
}
|
||||
|
||||
console.log(
|
||||
`[nextPlay] 尝试播放: ${nextSong.name}, 索引: ${currentIndex} -> ${nowPlayListIndex}, 单曲重试: ${singleTrackRetryCount}/${SINGLE_TRACK_MAX_RETRIES}, 连续失败: ${consecutiveFailCount.value}/${MAX_CONSECUTIVE_FAILS}`
|
||||
);
|
||||
@@ -591,6 +597,20 @@ export const usePlaylistStore = defineStore(
|
||||
sound.play();
|
||||
// 在恢复播放时也进行状态检测,防止URL已过期导致无声
|
||||
playerCore.checkPlaybackState(playerCore.playMusic);
|
||||
} else {
|
||||
console.warn('[PlaylistStore.setPlay] 无可用音频实例,尝试重建播放链路');
|
||||
const recoverSong = {
|
||||
...playerCore.playMusic,
|
||||
isFirstPlay: true,
|
||||
playMusicUrl: playerCore.playMusic.playMusicUrl?.startsWith('local://')
|
||||
? playerCore.playMusic.playMusicUrl
|
||||
: undefined
|
||||
};
|
||||
const recovered = await playerCore.handlePlayMusic(recoverSong, true);
|
||||
if (!recovered) {
|
||||
playerCore.setIsPlay(false);
|
||||
message.error(i18n.global.t('player.playFailed'));
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user