@@ -113,7 +113,12 @@ class Player {
113113 const errorCallback = ( e : Event ) => {
114114 const playSongData = songManager . getPlaySongData ( ) ;
115115 console . error ( "❌ song error:" , playSongData , e ) ;
116- this . handlePlaybackError ( ) ;
116+ // 提取错误码
117+ let errCode : number | undefined ;
118+ if ( "detail" in e && e . detail ) {
119+ errCode = ( e . detail as { errorCode ?: number } ) . errorCode ;
120+ }
121+ this . handlePlaybackError ( errCode ) ;
117122 } ;
118123 audioManager . on ( "error" , errorCallback ) ;
119124 this . eventCallbacks . set ( "error" , errorCallback ) ;
@@ -301,19 +306,28 @@ class Player {
301306 const dataStore = useDataStore ( ) ;
302307 const playSongData = songManager . getPlaySongData ( ) ;
303308 const currentSongId = playSongData ?. type === "radio" ? playSongData . dj ?. id : playSongData ?. id ;
309+ // 保存当前播放进度,用于恢复
310+ const currentSeek = this . getSeek ( ) ;
304311 // 初始化/切换曲目时重置计数
305312 if ( ! this . retryInfo . songId || this . retryInfo . songId !== Number ( currentSongId || 0 ) ) {
306313 this . retryInfo = { songId : Number ( currentSongId || 0 ) , count : 0 } ;
307314 }
308315 this . retryInfo . count += 1 ;
309- // 错误码 2:资源过期或临时网络错误
316+ // 2:资源过期或临时网络错误(通常是长时间暂停导致URL过期)
310317 if ( errCode === 2 && this . retryInfo . count <= 2 ) {
311- await this . initPlayer ( true , this . getSeek ( ) ) ;
318+ console . log ( "🔄 检测到资源过期,重新获取播放地址并从原位置继续:" , currentSeek ) ;
319+ await this . initPlayer ( true , currentSeek ) ;
312320 return ;
313321 }
314- // 其它错误:最多 3 次
322+ // 其它错误:最多 3 次,首次重试从原位置开始
315323 if ( this . retryInfo . count <= 3 ) {
316- await this . initPlayer ( true , 0 ) ;
324+ const seekPosition = this . retryInfo . count === 1 ? currentSeek : 0 ;
325+ console . log ( "🔄 播放出错,尝试重试:" , { count : this . retryInfo . count , seekPosition } ) ;
326+ // 只在第一次重试时显示提示,避免过于频繁
327+ if ( this . retryInfo . count === 1 ) {
328+ window . $message . info ( "播放出现问题,正在尝试恢复..." ) ;
329+ }
330+ await this . initPlayer ( true , seekPosition ) ;
317331 return ;
318332 }
319333 // 超过次数:切到下一首或清空
0 commit comments