@@ -68,7 +68,7 @@ interface SourceRetryState {
6868 */
6969type LoadSourceResult =
7070 | { status : "loaded" ; result : LoadOutcome ; resolved : ResolvedTrackSource }
71- | { status : "unresolved" }
71+ | { status : "unresolved" ; error ?: string }
7272 | { status : "cancelled" } ;
7373
7474/** 引擎 load 竞态 token */
@@ -233,8 +233,11 @@ const createSourceRetryState = (): SourceRetryState => ({
233233const resolveTrackSourceWithRetry = (
234234 track : Track ,
235235 retry : SourceRetryState ,
236+ onError : ( error : string ) => void ,
236237) : Promise < ResolvedTrackSource | null > =>
237238 resolveTrackSource ( track , {
239+ silent : true ,
240+ onError,
238241 skipOfficialOnline : retry . skipOfficialOnline ,
239242 skipPluginIds : [ ...retry . skippedPluginIds ] ,
240243 } ) ;
@@ -260,9 +263,6 @@ const markRetryableSourceFailure = (
260263 return false ;
261264} ;
262265
263- const shouldSuppressLoadError = ( resolved : ResolvedTrackSource ) : boolean =>
264- resolved . provider === "official" || resolved . provider === "plugin" ;
265-
266266/**
267267 * 解析并加载 Track,遇到可兜底的音源失败时继续尝试下一个来源
268268 * @param track - 要加载的 Track
@@ -285,18 +285,26 @@ const loadTrackSourceWithFallback = async (
285285) : Promise < LoadSourceResult > => {
286286 const retry = createSourceRetryState ( ) ;
287287 let firstTry = initialResolved ?? null ;
288+ let lastFailure : Extract < LoadSourceResult , { status : "loaded" } > | undefined ;
288289 while ( true ) {
289290 const usingInitial = firstTry !== null ;
290- const resolved = firstTry ?? ( await resolveTrackSourceWithRetry ( track , retry ) ) ;
291+ let resolutionError : string | undefined ;
292+ const resolved =
293+ firstTry ??
294+ ( await resolveTrackSourceWithRetry ( track , retry , ( error ) => {
295+ resolutionError = error ;
296+ } ) ) ;
291297 firstTry = null ;
292298 if ( ! shouldContinue ( ) ) return { status : "cancelled" } ;
293- if ( ! resolved ) return { status : "unresolved" } ;
299+ // 没有可用插件不代表原音源失败原因,优先保留实际加载错误
300+ if ( ! resolved ) return lastFailure ?? { status : "unresolved" , error : resolutionError } ;
294301 const result = await load ( resolved . source , autoPlay , track , {
295302 preparedId : usingInitial ? preparedId : undefined ,
296- suppressErrorToast : usingInitial || shouldSuppressLoadError ( resolved ) ,
303+ suppressErrorToast : true ,
297304 context,
298305 } ) ;
299306 if ( ! shouldContinue ( ) ) return { status : "cancelled" } ;
307+ if ( ! result . ok ) lastFailure = { status : "loaded" , result, resolved } ;
300308 // 预载 URL 可能已经过期,非本地来源失败后重新解析一次最新地址
301309 if (
302310 usingInitial &&
@@ -308,6 +316,8 @@ const loadTrackSourceWithFallback = async (
308316 }
309317 const canRetry =
310318 ! result . ok &&
319+ result . error !== ErrorCode . NETWORK_ERROR &&
320+ result . error !== ErrorCode . NETWORK_TIMEOUT &&
311321 ( retryOnAnyFailure || Boolean ( result . error && isSkippableError ( result . error ) ) ) &&
312322 markRetryableSourceFailure ( resolved , retry ) ;
313323 if ( canRetry ) continue ;
@@ -379,7 +389,8 @@ const loadTrack = async (
379389 status . state = "idle" ;
380390 void window . api . player . stop ( ) ;
381391 useMediaStore ( ) . setLyric ( null , null ) ;
382- shouldSkip = true ;
392+ if ( loaded . error ) handleError ( loaded . error ) ;
393+ shouldSkip = Boolean ( loaded . error && isSkippableError ( loaded . error ) ) ;
383394 } else {
384395 const { result, resolved } = loaded ;
385396 if ( ! result . ok && result . error && isSkippableError ( result . error ) ) {
@@ -435,10 +446,14 @@ export const reloadCurrentTrack = async (forcePlay?: boolean): Promise<boolean>
435446 // 被更新的加载接管:由它负责结果,不算本次失败
436447 if ( loaded . status === "cancelled" ) return true ;
437448 if ( loaded . status === "unresolved" ) {
449+ if ( loaded . error ) handleError ( loaded . error ) ;
438450 status . trackLoading = false ;
439451 return false ;
440452 }
441- if ( ! loaded . result . ok ) return false ;
453+ if ( ! loaded . result . ok ) {
454+ if ( loaded . result . error ) handleError ( loaded . result . error ) ;
455+ return false ;
456+ }
442457 if ( resumePosition > 0 ) await seek ( resumePosition ) ;
443458 if ( shouldPlay ) await play ( ) ;
444459 if ( loaded . resolved . cacheRequest ) {
0 commit comments