diff --git a/cmd/daemon/player.go b/cmd/daemon/player.go index 97f9c74..9bcb6ec 100644 --- a/cmd/daemon/player.go +++ b/cmd/daemon/player.go @@ -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 } @@ -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 {