Reputation: 372
Example: I have a Spotify album and I want to play its 15th track. After track 15 is finished playing I want Spotify to play track 16, after that track 17 and so on.
I am using the Spotify App Remote SDK for Android. I can think of three possible solutions.
Solutions:
Get the following tracks of the album through the Spotify Web API and add them to the queque. This one does not work for me though because I do not want Spotify to keep the queque when the user starts playing another playlist or album.
Use a background service that automatically starts playing the next track when the current one is finished. But here the user can experience a significant delay between the tracks.
Start the album and skip multiple times. This option would theoretically work. It does not seem to be a very elegant though.
Is there a better way to achieve this? Like for example somehow adding a context to the track? Thanks for any help!
Upvotes: 3
Views: 1264
Reputation: 1
With the method:
mSpotifyAppRemote.getPlayerApi().skipToIndex(java.lang.String uri, int index)
you have to put the uri with the context, for example an album:
"spotify:album:5ht7ItJgpBH7W6vJ5BqpPr"
and in the prameter index you need to put the position of the track in the album.
You can find more methods in the javadocs of SpotifyAppRemote here: https://spotify.github.io/android-sdk/app-remote-lib/docs/
Upvotes: 0
Reputation: 96
There is a good sample code Start/Resume a User's Playback how you can achieve it.
{
"context_uri": "spotify:album:5ht7ItJgpBH7W6vJ5BqpPr",
"offset": {
"position": 5
},
"position_ms": 0
}
Set the context_uri
to your album id, and offset
to your track number and position_ms
to your position in milliseconds.
Upvotes: 3