简体   繁体   中英

Remove tracks from playlist in spotify

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM