4
votes

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:

  1. 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.

  2. 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.

  3. 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!

2
why is solution 1 a problem? Can't you just delete the queue when a song outside the current album is played?snus74
Not if the app is gets closed by the user before...Stefan
Delete the queue when the app is killed? Option 1 really seems to be the solution hereAmin
Deleting the queue when the app is killed does not work in this case since the album should keep playing, even when the app is not open any more. But when the user starts another album/playlist the queue should not no longer exist.Stefan

2 Answers

3
votes

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.

0
votes

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/