0

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.

4

1 回答 1

0

Apparently elements of snapshot.toArray() are not the same as snapshot.ref(index).

Update: reference documentation that made me understand this - https://developer.spotify.com/docs/apps/api/1.0/api-models-reference.html

于 2013-10-16T20:53:59.850 回答