@@ -13,50 +13,69 @@ export const getLyricData = async (id: number) => {
1313 const musicStore = useMusicStore ( ) ;
1414 const settingStore = useSettingStore ( ) ;
1515 const statusStore = useStatusStore ( ) ;
16+ // 切歌或重新获取时,先标记为加载中
17+ statusStore . lyricLoading = true ;
1618
1719 if ( ! id ) {
1820 statusStore . usingTTMLLyric = false ;
1921 resetSongLyric ( ) ;
22+ statusStore . lyricLoading = false ;
2023 return ;
2124 }
2225
2326 try {
2427 // 检测本地歌词覆盖
2528 const getLyric = getLyricFun ( settingStore . localLyricPath , id ) ;
26- const [ { lyric : lyricRes , isLocal : lyricLocal } , { lyric : ttmlContent , isLocal : ttmlLocal } ] =
27- await Promise . all ( [
28- getLyric ( "lrc " , songLyric ) ,
29- settingStore . enableTTMLLyric ? getLyric ( "ttml" , songLyricTTML ) : getLyric ( "ttml" ) ,
30- ] ) ;
29+ // 先加载 LRC,不阻塞到 TTML 完成
30+ const lrcPromise = getLyric ( "lrc" , songLyric ) ;
31+ const ttmlPromise = settingStore . enableTTMLLyric ? getLyric ( "ttml " , songLyricTTML ) : null ;
32+
33+ const { lyric : lyricRes , isLocal : lyricLocal } = await lrcPromise ;
3134 parsedLyricsData ( lyricRes , lyricLocal && ! settingStore . enableExcludeLocalLyrics ) ;
32- if ( ttmlContent ) {
33- const parsedResult = parseTTML ( ttmlContent ) ;
34- if ( ! parsedResult ?. lines ?. length ) {
35- statusStore . usingTTMLLyric = false ;
36- return ;
37- }
38- const skipExcludeLocal = ttmlLocal && ! settingStore . enableExcludeLocalLyrics ;
39- const skipExcludeTTML = ! settingStore . enableExcludeTTML ;
40- const skipExclude = skipExcludeLocal || skipExcludeTTML ;
41- const ttmlLyric = parseTTMLToAMLL ( parsedResult , skipExclude ) ;
42- const ttmlYrcLyric = parseTTMLToYrc ( parsedResult , skipExclude ) ;
43- console . log ( "TTML lyrics:" , ttmlLyric , ttmlYrcLyric ) ;
44- // 合并数据
45- const updates : Partial < { yrcAMData : LyricLine [ ] ; yrcData : LyricType [ ] } > = { } ;
46- if ( ttmlLyric ?. length ) {
47- updates . yrcAMData = ttmlLyric ;
48- console . log ( "✅ TTML AMLL lyrics success" ) ;
49- }
50- if ( ttmlYrcLyric ?. length ) {
51- updates . yrcData = ttmlYrcLyric ;
52- console . log ( "✅ TTML Yrc lyrics success" ) ;
53- }
54- if ( Object . keys ( updates ) . length ) {
55- musicStore . setSongLyric ( updates ) ;
56- statusStore . usingTTMLLyric = true ;
57- } else {
58- statusStore . usingTTMLLyric = false ;
59- }
35+ // LRC 到达后即可认为加载完成
36+ statusStore . lyricLoading = false ;
37+
38+ // TTML 并行加载,完成后增量更新,不阻塞整体流程
39+ if ( ttmlPromise ) {
40+ statusStore . usingTTMLLyric = false ;
41+ void ttmlPromise
42+ . then ( ( { lyric : ttmlContent , isLocal : ttmlLocal } ) => {
43+ if ( ! ttmlContent ) {
44+ statusStore . usingTTMLLyric = false ;
45+ return ;
46+ }
47+ const parsedResult = parseTTML ( ttmlContent ) ;
48+ if ( ! parsedResult ?. lines ?. length ) {
49+ statusStore . usingTTMLLyric = false ;
50+ return ;
51+ }
52+ const skipExcludeLocal = ttmlLocal && ! settingStore . enableExcludeLocalLyrics ;
53+ const skipExcludeTTML = ! settingStore . enableExcludeTTML ;
54+ const skipExclude = skipExcludeLocal || skipExcludeTTML ;
55+ const ttmlLyric = parseTTMLToAMLL ( parsedResult , skipExclude ) ;
56+ const ttmlYrcLyric = parseTTMLToYrc ( parsedResult , skipExclude ) ;
57+ console . log ( "TTML lyrics:" , ttmlLyric , ttmlYrcLyric ) ;
58+ // 合并数据
59+ const updates : Partial < { yrcAMData : LyricLine [ ] ; yrcData : LyricType [ ] } > = { } ;
60+ if ( ttmlLyric ?. length ) {
61+ updates . yrcAMData = ttmlLyric ;
62+ console . log ( "✅ TTML AMLL lyrics success" ) ;
63+ }
64+ if ( ttmlYrcLyric ?. length ) {
65+ updates . yrcData = ttmlYrcLyric ;
66+ console . log ( "✅ TTML Yrc lyrics success" ) ;
67+ }
68+ if ( Object . keys ( updates ) . length ) {
69+ musicStore . setSongLyric ( updates ) ;
70+ statusStore . usingTTMLLyric = true ;
71+ } else {
72+ statusStore . usingTTMLLyric = false ;
73+ }
74+ } )
75+ . catch ( ( err ) => {
76+ console . error ( "❌ Error loading TTML lyrics:" , err ) ;
77+ statusStore . usingTTMLLyric = false ;
78+ } ) ;
6079 } else {
6180 statusStore . usingTTMLLyric = false ;
6281 }
@@ -66,6 +85,7 @@ export const getLyricData = async (id: number) => {
6685 console . error ( "❌ Error loading lyrics:" , error ) ;
6786 statusStore . usingTTMLLyric = false ;
6887 resetSongLyric ( ) ;
88+ statusStore . lyricLoading = false ;
6989 }
7090} ;
7191
0 commit comments