Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix skipping to the wrong song #61

Merged
merged 5 commits into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion cmd/daemon/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,16 @@ func (p *AppPlayer) handlePlayerCommand(req dealer.RequestPayload) error {
p.state.player.Options.RepeatingContext = req.Command.Options.PlayerOptionsOverride.RepeatingContext

var skipTo skipToFunc
if len(req.Command.Options.SkipTo.TrackUri) > 0 || len(req.Command.Options.SkipTo.TrackUid) > 0 {
if len(req.Command.Options.SkipTo.TrackUri) > 0 || len(req.Command.Options.SkipTo.TrackUid) > 0 || req.Command.Options.SkipTo.TrackIndex > 0 {
index := -1
skipTo = func(track *connectpb.ContextTrack) bool {
if len(req.Command.Options.SkipTo.TrackUid) > 0 && req.Command.Options.SkipTo.TrackUid == track.Uid {
return true
} else if len(req.Command.Options.SkipTo.TrackUri) > 0 && req.Command.Options.SkipTo.TrackUri == track.Uri {
return true
} else if req.Command.Options.SkipTo.TrackIndex != 0 {
index += 1
return index == req.Command.Options.SkipTo.TrackIndex
} else {
return false
}
Expand Down Expand Up @@ -261,6 +265,25 @@ func (p *AppPlayer) handlePlayerCommand(req dealer.RequestPayload) error {
case "skip_prev":
return p.skipPrev()
case "skip_next":
if req.Command.Track != nil {
contextSpotType := librespot.InferSpotifyIdTypeFromContextUri(p.state.player.ContextUri)
if err := p.state.tracks.TrySeek(tracks.ContextTrackComparator(contextSpotType, req.Command.Track)); err != nil {
return err
}

p.state.player.Timestamp = time.Now().UnixMilli()
p.state.player.PositionAsOfTimestamp = 0

p.state.player.Track = p.state.tracks.CurrentTrack()
p.state.player.PrevTracks = p.state.tracks.PrevTracks()
p.state.player.NextTracks = p.state.tracks.NextTracks()
p.state.player.Index = p.state.tracks.Index()

if err := p.loadCurrentTrack(p.state.player.IsPaused, true); err != nil {
return err
}
return nil
}
return p.skipNext()
case "update_context":
if req.Command.Context.Uri != p.state.player.ContextUri {
Expand Down
Loading