Fix refreshing of lyrics viewer on song change
This commit is contained in:
@@ -203,17 +203,18 @@ func (a *NowPlayingPage) OnSongChange(song, lastScrobbledIfAny *mediaprovider.Tr
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
go func() {
|
if lp, ok := a.sm.Server.(mediaprovider.LyricsProvider); ok {
|
||||||
if lp, ok := a.sm.Server.(mediaprovider.LyricsProvider); ok {
|
go func() {
|
||||||
lyrics, err := lp.GetLyrics(song)
|
if lyrics, err := lp.GetLyrics(song); err == nil {
|
||||||
if err == nil {
|
|
||||||
a.lyricsViewer.SetLyrics(lyrics)
|
a.lyricsViewer.SetLyrics(lyrics)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Error fetching lyrics: %v", err)
|
log.Printf("Error fetching lyrics: %v", err)
|
||||||
a.lyricsViewer.SetLyrics(nil)
|
a.lyricsViewer.SetLyrics(nil)
|
||||||
}
|
}
|
||||||
}
|
}()
|
||||||
}()
|
} else {
|
||||||
|
a.lyricsViewer.SetLyrics(nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *NowPlayingPage) OnPlayQueueChange() {
|
func (a *NowPlayingPage) OnPlayQueueChange() {
|
||||||
|
|||||||
@@ -13,9 +13,18 @@ type LyricsViewer struct {
|
|||||||
noLyricsLabel widget.Label
|
noLyricsLabel widget.Label
|
||||||
unsyncedViewer *widget.RichText
|
unsyncedViewer *widget.RichText
|
||||||
|
|
||||||
container *container.Scroll
|
container *container.Scroll
|
||||||
|
currentView lyricView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type lyricView int
|
||||||
|
|
||||||
|
const (
|
||||||
|
lyricViewEmpty lyricView = iota
|
||||||
|
lyricViewUnsynced
|
||||||
|
lyricViewSynced
|
||||||
|
)
|
||||||
|
|
||||||
func NewLyricsViewer() *LyricsViewer {
|
func NewLyricsViewer() *LyricsViewer {
|
||||||
l := &LyricsViewer{noLyricsLabel: widget.Label{
|
l := &LyricsViewer{noLyricsLabel: widget.Label{
|
||||||
Text: "Lyrics not available",
|
Text: "Lyrics not available",
|
||||||
@@ -27,8 +36,11 @@ func NewLyricsViewer() *LyricsViewer {
|
|||||||
|
|
||||||
func (l *LyricsViewer) SetLyrics(lyrics *mediaprovider.Lyrics) {
|
func (l *LyricsViewer) SetLyrics(lyrics *mediaprovider.Lyrics) {
|
||||||
if lyrics == nil || len(lyrics.Lines) == 0 {
|
if lyrics == nil || len(lyrics.Lines) == 0 {
|
||||||
l.container.Content = &l.noLyricsLabel
|
if l.currentView != lyricViewEmpty {
|
||||||
l.Refresh()
|
l.container.Content = &l.noLyricsLabel
|
||||||
|
l.currentView = lyricViewEmpty
|
||||||
|
l.Refresh()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +48,7 @@ func (l *LyricsViewer) SetLyrics(lyrics *mediaprovider.Lyrics) {
|
|||||||
l.unsyncedViewer = widget.NewRichText()
|
l.unsyncedViewer = widget.NewRichText()
|
||||||
l.unsyncedViewer.Wrapping = fyne.TextWrapWord
|
l.unsyncedViewer.Wrapping = fyne.TextWrapWord
|
||||||
}
|
}
|
||||||
l.unsyncedViewer.Segments = l.unsyncedViewer.Segments[:0]
|
l.unsyncedViewer.Segments = nil
|
||||||
for _, line := range lyrics.Lines {
|
for _, line := range lyrics.Lines {
|
||||||
ts := &widget.TextSegment{Text: line.Text}
|
ts := &widget.TextSegment{Text: line.Text}
|
||||||
ts.Style.Alignment = fyne.TextAlignCenter
|
ts.Style.Alignment = fyne.TextAlignCenter
|
||||||
@@ -44,8 +56,12 @@ func (l *LyricsViewer) SetLyrics(lyrics *mediaprovider.Lyrics) {
|
|||||||
ts.Style.Inline = false
|
ts.Style.Inline = false
|
||||||
l.unsyncedViewer.Segments = append(l.unsyncedViewer.Segments, ts)
|
l.unsyncedViewer.Segments = append(l.unsyncedViewer.Segments, ts)
|
||||||
}
|
}
|
||||||
l.container.Content = l.unsyncedViewer
|
l.unsyncedViewer.Refresh()
|
||||||
l.Refresh()
|
if l.currentView != lyricViewUnsynced {
|
||||||
|
l.container.Content = l.unsyncedViewer
|
||||||
|
l.currentView = lyricViewUnsynced
|
||||||
|
l.Refresh()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LyricsViewer) CreateRenderer() fyne.WidgetRenderer {
|
func (l *LyricsViewer) CreateRenderer() fyne.WidgetRenderer {
|
||||||
|
|||||||
Reference in New Issue
Block a user