update slider once per second always
This commit is contained in:
@@ -32,9 +32,7 @@ func NewPlaybackManager(ctx context.Context, cli *subsonic.Client, p *player.Pla
|
||||
for _, cb := range pm.onSongChange {
|
||||
cb(pm.NowPlaying())
|
||||
}
|
||||
if pm.pollingTick != nil {
|
||||
pm.pollingTick.Reset(pm.getPollSpeed())
|
||||
}
|
||||
pm.doUpdateTimePos()
|
||||
})
|
||||
p.OnSeek(func() {
|
||||
pm.doUpdateTimePos()
|
||||
@@ -106,25 +104,10 @@ func (p *PlaybackManager) PlayAlbum(albumID string) error {
|
||||
return p.player.PlayFromBeginning()
|
||||
}
|
||||
|
||||
// depending on the length of the current track, we need to poll
|
||||
// faster or less fast to make track position scroll bar look smooth
|
||||
func (p *PlaybackManager) getPollSpeed() time.Duration {
|
||||
t := p.player.GetStatus().Duration
|
||||
if t < 30 {
|
||||
return 100 * time.Millisecond
|
||||
} else if t < 90 {
|
||||
return 150 * time.Millisecond
|
||||
} else if t < 120 {
|
||||
return 250 * time.Millisecond
|
||||
} else {
|
||||
return 333 * time.Millisecond
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PlaybackManager) startPollTimePos() {
|
||||
ctx, cancel := context.WithCancel(p.ctx)
|
||||
p.cancelPollPos = cancel
|
||||
p.pollingTick = time.NewTicker(p.getPollSpeed())
|
||||
p.pollingTick = time.NewTicker(250 * time.Millisecond)
|
||||
|
||||
// TODO: fix occasional nil pointer dereference on app quit
|
||||
go func() {
|
||||
@@ -153,4 +136,7 @@ func (p *PlaybackManager) stopPollTimePos() {
|
||||
p.cancelPollPos()
|
||||
p.cancelPollPos = nil
|
||||
}
|
||||
if p.pollingTick != nil {
|
||||
p.pollingTick.Stop()
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -375,7 +375,7 @@ func (p *Player) eventHandler(ctx context.Context) {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
default:
|
||||
e := p.mpv.WaitEvent(0.2 /*timeout seconds*/)
|
||||
e := p.mpv.WaitEvent(1 /*timeout seconds*/)
|
||||
if e.Event_Id != mpv.EVENT_NONE {
|
||||
//log.Printf("mpv event: %+v\n", e)
|
||||
}
|
||||
|
||||
@@ -148,9 +148,8 @@ func (pc *PlayerControls) doPlayTimeUpdate(curTime, totalTime float64) {
|
||||
pc.curTimeLabel.SetText(ct)
|
||||
updated = true
|
||||
}
|
||||
if totalTime < 210 || updated {
|
||||
// if current track is long, we only need to redraw the slider
|
||||
// when the time label updates, to reduce screen redraws.
|
||||
if updated {
|
||||
// Only update slider once a second when time label changes
|
||||
pc.slider.SetValue(v)
|
||||
}
|
||||
}
|
||||
|
||||
+5
-2
@@ -1,13 +1,16 @@
|
||||
package ui
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
func SecondsToTimeString(s float64) string {
|
||||
if s < 0 {
|
||||
s = 0
|
||||
}
|
||||
min := int(s / 60)
|
||||
sec := int(s - float64(min*60))
|
||||
sec := int(math.Round(s - float64(min*60)))
|
||||
|
||||
return fmt.Sprintf("%2d:%02d", min, sec)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user