make sure to jump straight to correct lyric for the first time update

This commit is contained in:
Drew Weymouth
2024-05-18 16:26:36 -07:00
parent 2e62bdf01d
commit d8ebc17566
+7 -1
View File
@@ -17,6 +17,10 @@ type LyricsViewer struct {
nextLyricLine int nextLyricLine int
lastPlayPos float64 lastPlayPos float64
// keeps track if UpdatePlayPos has been called yet
// for the current lyrics
firstUpdate bool
container *fyne.Container container *fyne.Container
isEmpty bool isEmpty bool
} }
@@ -33,6 +37,7 @@ func NewLyricsViewer() *LyricsViewer {
func (l *LyricsViewer) SetLyrics(lyrics *mediaprovider.Lyrics) { func (l *LyricsViewer) SetLyrics(lyrics *mediaprovider.Lyrics) {
l.lyrics = lyrics l.lyrics = lyrics
l.nextLyricLine = 0 l.nextLyricLine = 0
l.firstUpdate = true
if lyrics == nil || len(lyrics.Lines) == 0 { if lyrics == nil || len(lyrics.Lines) == 0 {
if !l.isEmpty { if !l.isEmpty {
l.container.Objects[0] = &l.noLyricsLabel l.container.Objects[0] = &l.noLyricsLabel
@@ -62,8 +67,9 @@ func (l *LyricsViewer) UpdatePlayPos(timeSecs float64) {
if l.lyrics == nil || !l.lyrics.Synced { if l.lyrics == nil || !l.lyrics.Synced {
return return
} }
if timeSecs < l.lastPlayPos { if l.firstUpdate || timeSecs < l.lastPlayPos {
l.OnSeeked(timeSecs) l.OnSeeked(timeSecs)
l.firstUpdate = false
return return
} }
l.lastPlayPos = timeSecs l.lastPlayPos = timeSecs