From 429194a65085ad908d8bf2976a999ffdfb13169b Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 3 Oct 2024 18:33:11 +0200 Subject: [PATCH] fix: don't seek to the start when swiping right The API has an extra parameter `allow_seeking` that indicates whether the seek left is due to pressing the "prev" button, or because the album is swiped right to go to the previous track immediately. This patch adds support for this feature. There's still one issue however: when going to the previous song, the player will for a short time show the first track in an album. Not sure why, I suspect go-librespot doesn't send the whole queue (so the player doesn't know there are other tracks in the album). --- cmd/daemon/controls.go | 4 ++-- cmd/daemon/player.go | 4 ++-- dealer/recv.go | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/daemon/controls.go b/cmd/daemon/controls.go index 1864e4a..2a9d4ba 100644 --- a/cmd/daemon/controls.go +++ b/cmd/daemon/controls.go @@ -416,8 +416,8 @@ func (p *AppPlayer) seek(position int64) error { return nil } -func (p *AppPlayer) skipPrev() error { - if p.player.PositionMs() > 3000 { +func (p *AppPlayer) skipPrev(allowSeeking bool) error { + if allowSeeking && p.player.PositionMs() > 3000 { return p.seek(0) } diff --git a/cmd/daemon/player.go b/cmd/daemon/player.go index 78fc8cf..392d56a 100644 --- a/cmd/daemon/player.go +++ b/cmd/daemon/player.go @@ -277,7 +277,7 @@ func (p *AppPlayer) handlePlayerCommand(req dealer.RequestPayload) error { return nil case "skip_prev": - return p.skipPrev() + return p.skipPrev(req.Command.Options.AllowSeeking) case "skip_next": if req.Command.Track != nil { contextSpotType := librespot.InferSpotifyIdTypeFromContextUri(p.state.player.ContextUri) @@ -441,7 +441,7 @@ func (p *AppPlayer) handleApiRequest(req ApiRequest) (any, error) { _ = p.seek(position) return nil, nil case ApiRequestTypePrev: - _ = p.skipPrev() + _ = p.skipPrev(true) return nil, nil case ApiRequestTypeNext: _ = p.skipNext() diff --git a/dealer/recv.go b/dealer/recv.go index 0358f77..51054e8 100644 --- a/dealer/recv.go +++ b/dealer/recv.go @@ -69,6 +69,7 @@ type RequestPayload struct { RestorePosition string `json:"restore_position"` RestoreTrack string `json:"restore_track"` AlwaysPlaySomething bool `json:"always_play_something"` + AllowSeeking bool `json:"allow_seeking"` SkipTo struct { TrackUid string `json:"track_uid"` TrackUri string `json:"track_uri"`