mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-28 10:57:23 +08:00
🐞 fix: 修复刷新后第一次播放出现的无法播放问题
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ export interface SongResult {
|
|||||||
// 时长
|
// 时长
|
||||||
duration?: number;
|
duration?: number;
|
||||||
dt?: number;
|
dt?: number;
|
||||||
|
isFirstPlay?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Song {
|
export interface Song {
|
||||||
|
|||||||
Reference in New Issue
Block a user