I’ve been experimenting with the Spotify API and am trying to play a playlist using player.play(). My code looks like this:
models = sp.require("sp://import/scripts/api/models");
player = models.player;
playlist = new models.Playlist();
playlist.add("a track uri");
playlist.add("a track uri also");
track = models.Track.fromURI(playlist.get(0).data.uri);
player.play(track.data.uri, playlist.data.uri);
This code plays the first track for me but when the song ends or I press next, the player goes to a ‘null’ state with no tracks queued up. In other words, it acts as if it doesn’t have any more tracks to play. The official API is lacking in depth on the topic of context.
Note: I would like my playlist to be ephemeral but a persistent one is fine as a starting point.
I had a mistake in another part of my code that was causing this unintended behavior. The above code works fine.