first draft of synced lyrics integration, missing seek support
This commit is contained in:
@@ -241,8 +241,9 @@ func (s *nowPlayingPageState) Restore() Page {
|
|||||||
|
|
||||||
var _ CanShowPlayTime = (*NowPlayingPage)(nil)
|
var _ CanShowPlayTime = (*NowPlayingPage)(nil)
|
||||||
|
|
||||||
func (a *NowPlayingPage) OnPlayTimeUpdate(_, _ float64) {
|
func (a *NowPlayingPage) OnPlayTimeUpdate(curTime, _ float64) {
|
||||||
a.formatStatusLine()
|
a.formatStatusLine()
|
||||||
|
a.lyricsViewer.UpdatePlayPos(curTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ CanSelectAll = (*NowPlayingPage)(nil)
|
var _ CanSelectAll = (*NowPlayingPage)(nil)
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ type LyricsViewer struct {
|
|||||||
|
|
||||||
noLyricsLabel widget.Label
|
noLyricsLabel widget.Label
|
||||||
viewer *fynelyrics.LyricsViewer
|
viewer *fynelyrics.LyricsViewer
|
||||||
|
lyrics *mediaprovider.Lyrics
|
||||||
|
nextLyricLine int
|
||||||
|
|
||||||
container *fyne.Container
|
container *fyne.Container
|
||||||
isEmpty bool
|
isEmpty bool
|
||||||
@@ -28,6 +30,8 @@ func NewLyricsViewer() *LyricsViewer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *LyricsViewer) SetLyrics(lyrics *mediaprovider.Lyrics) {
|
func (l *LyricsViewer) SetLyrics(lyrics *mediaprovider.Lyrics) {
|
||||||
|
l.lyrics = lyrics
|
||||||
|
l.nextLyricLine = 0
|
||||||
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
|
||||||
@@ -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 {
|
func (l *LyricsViewer) CreateRenderer() fyne.WidgetRenderer {
|
||||||
return widget.NewSimpleRenderer(l.container)
|
return widget.NewSimpleRenderer(l.container)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user