From 086b6f7b5d13feb3eb3b9b06c3b9f08e4b916754 Mon Sep 17 00:00:00 2001 From: aditya-K2 Date: Wed, 12 Apr 2023 07:25:38 +0530 Subject: [PATCH] Use URI instead of position to play songs in RecentlyPlayedView --- spt/play.go | 7 +++++++ ui/view_recent.go | 12 ++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/spt/play.go b/spt/play.go index 5d70408..5332d3b 100644 --- a/spt/play.go +++ b/spt/play.go @@ -21,6 +21,13 @@ func PlaySongWithContext(context *spotify.URI, position int) error { }) } +func PlaySongWithContextURI(context, uri *spotify.URI) error { + return play(&spotify.PlayOptions{ + PlaybackContext: context, + PlaybackOffset: &spotify.PlaybackOffset{URI: *uri}, + }) +} + func PlayContext(context *spotify.URI) error { return play(&spotify.PlayOptions{ PlaybackContext: context, diff --git a/ui/view_recent.go b/ui/view_recent.go index 2b1353a..e85c72f 100644 --- a/ui/view_recent.go +++ b/ui/view_recent.go @@ -61,9 +61,17 @@ func (re *RecentlyPlayedView) ExternalInputCapture() func(e *tcell.EventKey) *tc return func(e *tcell.EventKey) *tcell.EventKey { if e.Key() == tcell.KeyEnter { r, _ := Ui.Main.Table.GetSelection() - if err := spt.PlaySong(re.recentlyPlayed[r].Track.URI); err != nil { - SendNotification(err.Error()) + contextUri := re.recentlyPlayed[r].PlaybackContext.URI + if string(contextUri) != "" { + if err := spt.PlaySongWithContextURI(&re.recentlyPlayed[r].PlaybackContext.URI, &re.recentlyPlayed[r].Track.URI); err != nil { + SendNotification(err.Error()) + } + } else { + if err := spt.PlaySong(re.recentlyPlayed[r].Track.URI); err != nil { + SendNotification(err.Error()) + } } + return nil } return e }