Want to delete all songs from the playlist up to the selected song. This code is crashing Spotify so I can't see what the complaint is but I believe its happening as soon as the first call to remove the track happens. If I comment out the remove call, the logging looks correct.
var playlist = models.Playlist.fromURI(uri);
playlist.load('tracks').done(function (tracks) {
console.log('tracks loaded');
playlist.tracks.snapshot(0, 20).done(function (snapshot) {
console.log('snapshot loaded');
if(snapshot.find(models.player.track)) {
var done=false;
var tracks = snapshot.toArray();
tracks.forEach(function(deleteme) {
if (deleteme == models.player.track) {
console.log('here\'s our current track');
done = true;
} else if (done) {
console.log('already done');
} else {
console.log('deleting ' + deleteme.uri);
playlist.tracks.remove(deleteme);
}
})
}
});
});
Update Not sure what happened, but its no longer crashing. Maybe because I'm running spotify -console from the command line.
Now I get this message instead.
20:39:36.663 A [base/range.h:27 ] Check failed: loc >= 0:
Promise.fail's error message says Item at index -1 changed.