I have a problem when executing this code:
require(['$api/models','$api/library#Library'], function(models,Library) {
// THIS ONLY HAPPEN FOR TOP LIST
var uri=Library.forCurrentUser().toplist.uri;
// IF YOU USE ANY OTHER PLAYLIST IT WORKS FINE
// var uri="spotify:user:vdesabou:playlist:0xy2zExFmPzJZsY0X0bCC5";
var playlist = models.Playlist.fromURI(uri);
playlist.load('tracks').done(function() {
console.log("loaded 1");
playlist.tracks.snapshot().done(function(snapshot) {
console.log("snapshot length 1 " + snapshot.length);
snapshot.loadAll('name')
.done(function(snap_tracks) { console.log("loaded tracks length 1 " + snap_tracks.length); })
.fail(function() { console.log("loadAll failed"); });
}).fail(function() { console.log("snapshot failed"); });
}).fail(function() { console.log("playlist load tracks failed"); });
});
If I execute multiple time (by reloading my application), I don't get results about 1 time out of 3
When it doesn't work:
loaded 1
When it works I get:
loaded 1
snapshot length 1 20
loaded tracks length 1 20
This is happening only for top list playlist, any other playlist is ok.
What could be wrong? Thanks
Library's toplist property is already a playlist, so you don't need to create a new Playlist object from its URI. This snippet does the same as yours, but loads the toplist property and uses it to get the tracks directly instead of creating a new playlist.
i did try the snippet you provided, and similarly to Thomas I couldn't find anything wrong with it. Hope this helps though.