Reputation: 512
How can I add a track to the current play queue in a Spotify app?
Upvotes: 5
Views: 4225
Reputation: 1100
You need to create an unnamed playlist to create your own play queue.
function playTracks(tracks, index) {
var pl = new models.Playlist();
for (var i = 0; i < tracks.length; ++i) {
pl.add(tracks[i]);
}
models.player.play(pl.uri, pl.uri, index);
}
Upvotes: 4
Reputation: 1648
The current play queue seems to be unavailable. But this snippet may be useful if your purpose is to build a queue...
// Create a name for a temporary playlist.
function temporaryName() {
return (Date.now() * Math.random()).toFixed();
}
function getTemporaryPlaylist() {
var temporaryPlaylist = sp.core.getTemporaryPlaylist(temporaryName());
sp.trackPlayer.setContextCanSkipPrev(temporaryPlaylist.uri, false);
sp.trackPlayer.setContextCanRepeat(temporaryPlaylist.uri, false);
sp.trackPlayer.setContextCanShuffle(temporaryPlaylist.uri, false);
return temporaryPlaylist;
}
var tpl = getTemporaryPlaylist();
tpl.add(trackUri);
tpl.add(track2Uri);
//...
sp.trackPlayer.playTrackFromContext(tpl.uri, 0, "", {
onSuccess: //...
onError: //...
onComplete: //...
});
Upvotes: 2
Reputation: 535
Nothing in the Apps API reference suggests that it is possible. There is no mention of how to do this in any of the apps in the preview build either. The conclusion has to be that doing this is not currently supported.
Upvotes: 0