SpotifyAPI-NET icon indicating copy to clipboard operation
SpotifyAPI-NET copied to clipboard

How to get the current playlist?

Open Nensec opened this issue 8 years ago • 3 comments

As the title says, I'm trying to get the current playing playlist.

The simple scenario is that I want to add items to it. The only option I can see right now is to create a new playlist and set the client to play that.

Nensec avatar Aug 28 '18 07:08 Nensec

~~I don't think there is an easy solution to this because a playlist is basically just a collection of trackURIs and since a track can be in multiple playlists there is no way to "backtrack" the playlist the track is coming from.~~

One solution could be to GetUserPlaylists() and check if any track in any playlist matches the currently playing track, which could cause problems if the user has the same track in multiple playlists.

A better solution but harder to implement would be to handle playlists completely within your program:

  • Retrieve users playlists and display them
  • Give the option to play them and save a reference to the selected playlist

The problem with this solution is that it doesn't work if the user uses spotify directly.

Gruhlum avatar Aug 28 '18 08:08 Gruhlum

Use the https://github.com/JohnnyCrazy/SpotifyAPI-NET/blob/601b74d3c1059b11749a9e14653d1da85df49d43/SpotifyAPI.Web/Models/PlaybackContext.cs#L21 provided by https://github.com/JohnnyCrazy/SpotifyAPI-NET/blob/4b7b2179b96084d98d93e4863a77b86b9bb0b0e5/SpotifyAPI.Web/SpotifyWebAPI.cs#L1919

Then you should be able to use the URI to fetch the playlist

https://github.com/JohnnyCrazy/SpotifyAPI-NET/blob/601b74d3c1059b11749a9e14653d1da85df49d43/SpotifyAPI.Web/Models/GeneralModels.cs#L145-L158

JohnnyCrazy avatar Aug 28 '18 08:08 JohnnyCrazy

Well that certainly took a few jumps and hoops. But thanks : )

Nensec avatar Aug 28 '18 09:08 Nensec