@@ -61,7 +61,6 @@ type NowPlayingPage struct {
6161 container * fyne.Container
6262
6363 // cancel funcs for background fetch tasks
64- lyricFetchCancel context.CancelFunc
6564 imageLoadCancel context.CancelFunc
6665 relatedFetchCancel context.CancelFunc
6766}
@@ -72,27 +71,27 @@ type nowPlayingPageState struct {
7271 pool * util.WidgetPool
7372 sm * backend.ServerManager
7473 pm * backend.PlaybackManager
74+ lm * backend.LyricsManager
7575 im * backend.ImageManager
7676 mp mediaprovider.MediaProvider
7777 canRate bool
7878 canShare bool
79- lrcFetch * backend.LrcLibFetcher
8079}
8180
8281func NewNowPlayingPage (
8382 conf * backend.NowPlayingPageConfig ,
8483 contr * controller.Controller ,
8584 pool * util.WidgetPool ,
8685 sm * backend.ServerManager ,
86+ lm * backend.LyricsManager ,
8787 im * backend.ImageManager ,
8888 pm * backend.PlaybackManager ,
8989 mp mediaprovider.MediaProvider ,
9090 canRate bool ,
9191 canShare bool ,
92- lrcLibFetcher * backend.LrcLibFetcher ,
9392) * NowPlayingPage {
9493 state := nowPlayingPageState {
95- conf : conf , contr : contr , pool : pool , sm : sm , im : im , pm : pm , mp : mp , canRate : canRate , canShare : canShare , lrcFetch : lrcLibFetcher ,
94+ conf : conf , contr : contr , pool : pool , sm : sm , lm : lm , im : im , pm : pm , mp : mp , canRate : canRate , canShare : canShare ,
9695 }
9796 if page , ok := pool .Obtain (util .WidgetTypeNowPlayingPage ).(* NowPlayingPage ); ok && page != nil {
9897 page .nowPlayingPageState = state
@@ -336,10 +335,6 @@ func (a *NowPlayingPage) onImageLoaded(img image.Image, err error) {
336335}
337336
338337func (a * NowPlayingPage ) updateLyrics () {
339- if a .lyricFetchCancel != nil {
340- a .lyricFetchCancel ()
341- }
342-
343338 if a .nowPlayingID == a .curLyricsID {
344339 if a .nowPlayingID != "" {
345340 // just need to sync the current time
@@ -354,8 +349,6 @@ func (a *NowPlayingPage) updateLyrics() {
354349 return
355350 }
356351 a .curLyricsID = a .nowPlayingID
357- ctx , cancel := context .WithCancel (context .Background ())
358- a .lyricFetchCancel = cancel
359352 a .lyricsLoading .Start ()
360353 // set the widget to an empty (not nil) lyric during fetch
361354 // to keep it from showing "Lyrics not available"
@@ -365,27 +358,11 @@ func (a *NowPlayingPage) updateLyrics() {
365358 Lines : []mediaprovider.LyricLine {{Text : "" }},
366359 })
367360 tr , _ := a .nowPlaying .(* mediaprovider.Track )
368- go a .fetchLyrics (ctx , tr )
369- }
370361
371- func (a * NowPlayingPage ) fetchLyrics (ctx context.Context , song * mediaprovider.Track ) {
372- var lyrics * mediaprovider.Lyrics
373- var err error
374- if lp , ok := a .sm .Server .(mediaprovider.LyricsProvider ); ok {
375- if lyrics , err = lp .GetLyrics (song ); err != nil {
376- log .Printf ("Error fetching lyrics: %v" , err )
377- }
378- }
379- if lyrics == nil && a .lrcFetch != nil {
380- lyrics , err = a .lrcFetch .FetchLrcLibLyrics (song .Title , song .ArtistNames [0 ], song .Album , int (song .Duration .Seconds ()))
381- if err != nil {
382- log .Println (err .Error ())
362+ a .lm .FetchLyricsAsync (tr , func (id string , lyrics * mediaprovider.Lyrics ) {
363+ if id != a .nowPlayingID {
364+ return
383365 }
384- }
385- select {
386- case <- ctx .Done ():
387- return
388- default :
389366 fyne .Do (func () {
390367 a .lyricsLoading .Stop ()
391368 a .lyricsViewer .EnableTapToSeek ()
@@ -395,7 +372,7 @@ func (a *NowPlayingPage) fetchLyrics(ctx context.Context, song *mediaprovider.Tr
395372 a .lyricsViewer .OnSeeked (a .lastPlayPos )
396373 }
397374 })
398- }
375+ })
399376}
400377
401378func (a * NowPlayingPage ) updateRelatedList () {
@@ -464,7 +441,7 @@ func (a *NowPlayingPage) Reload() {
464441}
465442
466443func (s * nowPlayingPageState ) Restore () Page {
467- return NewNowPlayingPage (s .conf , s .contr , s .pool , s .sm , s .im , s .pm , s .mp , s .canRate , s .canShare , s . lrcFetch )
444+ return NewNowPlayingPage (s .conf , s .contr , s .pool , s .sm , s .lm , s . im , s .pm , s .mp , s .canRate , s .canShare )
468445}
469446
470447var _ CanShowPlayTime = (* NowPlayingPage )(nil )
0 commit comments