@@ -70,22 +70,10 @@ class Player {
7070 private isStale ( sessionId : number ) : boolean {
7171 return sessionId !== this . playSessionId ;
7272 }
73- /**
74- * 保护执行:会话过期则早退
75- */
76- private guard < T > ( sessionId : number , fn : ( ) => T ) : T | undefined {
77- if ( this . isStale ( sessionId ) ) return ;
78- return fn ( ) ;
79- }
8073 /**
8174 * 重置底层播放器与定时器(幂等)
8275 */
8376 private resetPlayerCore ( ) {
84- try {
85- this . player ?. off ( ) ;
86- } catch {
87- /* empty */
88- }
8977 try {
9078 Howler . stop ( ) ;
9179 Howler . unload ( ) ;
@@ -248,23 +236,20 @@ class Player {
248236 // 自动播放
249237 if ( autoPlay ) await this . play ( ) ;
250238 // 获取歌曲附加信息 - 非电台和本地
251- if ( type !== "radio" && ! path ) {
252- runIdle ( ( ) => getLyricData ( id ) ) ;
253- } else resetSongLyric ( ) ;
239+ if ( type !== "radio" && ! path ) getLyricData ( id ) ;
240+ else resetSongLyric ( ) ;
254241 // 定时获取状态
255242 if ( ! this . playerInterval ) this . handlePlayStatus ( ) ;
256243 // 新增播放历史
257244 if ( type !== "radio" ) dataStore . setHistory ( musicStore . playSong ) ;
258245 // 获取歌曲封面主色
259246 if ( ! path ) runIdle ( ( ) => getCoverColor ( musicStore . songCover ) ) ;
260247 // 更新 MediaSession
261- if ( ! path ) runIdle ( ( ) => this . updateMediaSession ( ) ) ;
248+ if ( ! path ) this . updateMediaSession ( ) ;
262249 // 开发模式
263250 if ( isDev ) window . player = this . player ;
264251 // 预载下一首播放地址
265- runIdle ( ( ) => {
266- void this . prefetchNextSongUrl ( ) ;
267- } ) ;
252+ this . prefetchNextSongUrl ( ) ;
268253 }
269254 /**
270255 * 播放器事件
@@ -554,7 +539,7 @@ class Player {
554539 const { lyric, format } = await window . electron . ipcRenderer . invoke ( "get-music-lyric" , path ) ;
555540 parseLocalLyric ( lyric , format ) ;
556541 // 更新媒体会话
557- runIdle ( ( ) => this . updateMediaSession ( ) ) ;
542+ this . updateMediaSession ( ) ;
558543 } catch ( error ) {
559544 window . $message . error ( "获取本地歌曲元信息失败" ) ;
560545 console . error ( "Failed to parse local music info:" , error ) ;
@@ -595,7 +580,10 @@ class Player {
595580 try {
596581 // 获取播放数据
597582 const playSongData = getPlaySongData ( ) ;
598- if ( ! playSongData ) return ;
583+ if ( ! playSongData ) {
584+ statusStore . playLoading = false ;
585+ return ;
586+ }
599587 const { id, dj, path, type } = playSongData ;
600588 // 更改当前播放歌曲
601589 musicStore . playSong = playSongData ;
@@ -695,7 +683,7 @@ class Player {
695683 const settingStore = useSettingStore ( ) ;
696684 // 检查播放器状态
697685 if ( ! this . player || this . player . state ( ) === "unloaded" ) {
698- console . warn ( "⚠️ Player not ready for play ") ;
686+ window . $message . warning ( "播放器未加载完成,请稍后重试 ") ;
699687 return ;
700688 }
701689 // 已在播放
@@ -721,7 +709,6 @@ class Player {
721709 async pause ( changeStatus : boolean = true ) {
722710 const statusStore = useStatusStore ( ) ;
723711 const settingStore = useSettingStore ( ) ;
724- const localSession = this . playSessionId ;
725712
726713 // 播放器未加载完成或不存在
727714 if ( ! this . player || this . player . state ( ) !== "loaded" ) {
@@ -734,7 +721,7 @@ class Player {
734721 await new Promise < void > ( ( resolve ) => {
735722 this . player . fade ( statusStore . playVolume , 0 , settingStore . getFadeTime ) ;
736723 this . player . once ( "fade" , ( ) => {
737- this . guard ( localSession , ( ) => this . player . pause ( ) ) ;
724+ this . player . pause ( ) ;
738725 resolve ( ) ;
739726 } ) ;
740727 } ) ;
0 commit comments