Reputation: 196
I'm developing using Spotify Apps and I have a list of Spoftify URIs tracks that I want to play. Is there any way to create a dynamic temporary Playlist to reproduce them?
I've tried the following and Spotify crashes:
var myTemporaryPlaylist = new models.Playlist(); //I create a new Playlist object
myTemporaryPlaylist._collections(); //Then the "track" property appears
myTemporaryPlaylist.tracks.add(models.Track.fromURI('spotify:track:blablabla')) //being blablabla a real URI...
Any idea what I'm doing wrong? I don't know how to populate the Playlist with my URI Tracks...
I'm using 1.0 API if that helps.
Many thanks...!
Upvotes: 2
Views: 1091
Reputation: 4830
You can create a temporary playlist by using
var playlist = models.Playlist.createTemporary("My temporary playlist");
You shouldn't use the default constructor to create playlists. If you want to create a regular playlist, simply use the create method instead.
In order to add tracks to a playlist, you need to first load the playlist's tracks. This is done for performance reasons. For example,
models.Playlist.createTemporary("A temporary playlist").done(function(playlist) {
playlist.load("tracks").done(function(loadedPlaylist) {
loadedPlaylist.tracks.add(models.Track.fromURI("spotify:track:2Vy4z1ZUN7RvN7syWI2yef"));
loadedPlaylist.tracks.add(models.Track.fromURI("spotify:track:2pj2VXKSBRTmV8nuiaCKd2"));
});
});
Read more about playlists here.
Upvotes: 4