first draft of synced lyrics integration, missing seek support

This commit is contained in:
Drew Weymouth
2024-05-16 18:32:13 -07:00
parent 220d523f88
commit e8d751bc2a
2 changed files with 33 additions and 1 deletions
+2 -1
View File
@@ -241,8 +241,9 @@ func (s *nowPlayingPageState) Restore() Page {
var _ CanShowPlayTime = (*NowPlayingPage)(nil)
func (a *NowPlayingPage) OnPlayTimeUpdate(_, _ float64) {
func (a *NowPlayingPage) OnPlayTimeUpdate(curTime, _ float64) {
a.formatStatusLine()
a.lyricsViewer.UpdatePlayPos(curTime)
}
var _ CanSelectAll = (*NowPlayingPage)(nil)
+31
View File
@@ -13,6 +13,8 @@ type LyricsViewer struct {
noLyricsLabel widget.Label
viewer *fynelyrics.LyricsViewer
lyrics *mediaprovider.Lyrics
nextLyricLine int
container *fyne.Container
isEmpty bool
@@ -28,6 +30,8 @@ func NewLyricsViewer() *LyricsViewer {
}
func (l *LyricsViewer) SetLyrics(lyrics *mediaprovider.Lyrics) {
l.lyrics = lyrics
l.nextLyricLine = 0
if lyrics == nil || len(lyrics.Lines) == 0 {
if !l.isEmpty {
l.container.Objects[0] = &l.noLyricsLabel
@@ -53,6 +57,33 @@ func (l *LyricsViewer) SetLyrics(lyrics *mediaprovider.Lyrics) {
}
}
func (l *LyricsViewer) UpdatePlayPos(timeSecs float64) {
if l.lyrics == nil || !l.lyrics.Synced {
return
}
// advance if needed
if l.lyrics.Lines[l.nextLyricLine].Start <= timeSecs {
l.viewer.NextLine()
if l.nextLyricLine < len(l.lyrics.Lines) {
l.nextLyricLine++
}
}
}
func (l *LyricsViewer) OnSeeked(timeSecs float64) {
if l.lyrics == nil || !l.lyrics.Synced {
return
}
curLine := 0
for i, l := range l.lyrics.Lines {
if l.Start < timeSecs {
curLine = i + 1
break
}
}
l.viewer.SetCurrentLine(curLine)
}
func (l *LyricsViewer) CreateRenderer() fyne.WidgetRenderer {
return widget.NewSimpleRenderer(l.container)
}