hook up seek for synced lyrics

This commit is contained in:
Drew Weymouth
2024-05-16 19:22:08 -07:00
parent d156bf02e0
commit e7b2b821f3
6 changed files with 26 additions and 15 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ func NewBottomPanel(pm *backend.PlaybackManager, contr *controller.Controller) *
bp.ExtendBaseWidget(bp)
pm.OnSongChange(bp.onSongChange)
pm.OnPlayTimeUpdate(func(cur, total float64) {
pm.OnPlayTimeUpdate(func(cur, total float64, _ bool) {
if !pm.IsSeeking() {
bp.Controls.UpdatePlayTime(cur, total)
}
+3 -3
View File
@@ -46,7 +46,7 @@ type CanShowNowPlaying interface {
}
type CanShowPlayTime interface {
OnPlayTimeUpdate(curTime, totalTime float64)
OnPlayTimeUpdate(curTime, totalTime float64, seeked bool)
}
type CanShowPlayQueue interface {
@@ -222,12 +222,12 @@ func (b *BrowsingPane) onSongChange(song, lastScrobbledIfAny *mediaprovider.Trac
}
}
func (b *BrowsingPane) onPlayTimeUpdate(cur, total float64) {
func (b *BrowsingPane) onPlayTimeUpdate(cur, total float64, seeked bool) {
if b.curPage == nil {
return
}
if p, ok := b.curPage.(CanShowPlayTime); ok {
p.OnPlayTimeUpdate(cur, total)
p.OnPlayTimeUpdate(cur, total, seeked)
}
}
+6 -2
View File
@@ -241,9 +241,13 @@ func (s *nowPlayingPageState) Restore() Page {
var _ CanShowPlayTime = (*NowPlayingPage)(nil)
func (a *NowPlayingPage) OnPlayTimeUpdate(curTime, _ float64) {
func (a *NowPlayingPage) OnPlayTimeUpdate(curTime, _ float64, seeked bool) {
a.formatStatusLine()
a.lyricsViewer.UpdatePlayPos(curTime)
if seeked {
a.lyricsViewer.OnSeeked(curTime)
} else {
a.lyricsViewer.UpdatePlayPos(curTime)
}
}
var _ CanSelectAll = (*NowPlayingPage)(nil)
+7
View File
@@ -15,6 +15,7 @@ type LyricsViewer struct {
viewer *fynelyrics.LyricsViewer
lyrics *mediaprovider.Lyrics
nextLyricLine int
lastPlayPos float64
container *fyne.Container
isEmpty bool
@@ -61,6 +62,11 @@ func (l *LyricsViewer) UpdatePlayPos(timeSecs float64) {
if l.lyrics == nil || !l.lyrics.Synced {
return
}
if timeSecs < l.lastPlayPos {
l.OnSeeked(timeSecs)
return
}
l.lastPlayPos = timeSecs
// advance if needed
if l.lyrics.Lines[l.nextLyricLine].Start <= timeSecs {
l.viewer.NextLine()
@@ -71,6 +77,7 @@ func (l *LyricsViewer) UpdatePlayPos(timeSecs float64) {
}
func (l *LyricsViewer) OnSeeked(timeSecs float64) {
l.lastPlayPos = timeSecs
if l.lyrics == nil || !l.lyrics.Synced {
return
}