[英]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. 这段代码使Spotify崩溃了,所以我看不到抱怨是什么,但是我相信它是在首次调用删除曲目时发生的。 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. 也许是因为我从命令行运行spotify -console。
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. Promise.fail的错误消息说索引-1处的项目已更改。
Apparently elements of snapshot.toArray()
are not the same as snapshot.ref(index)
. 显然, snapshot.toArray()
元素与snapshot.ref(index)
。
Update: reference documentation that made me understand this - https://developer.spotify.com/docs/apps/api/1.0/api-models-reference.html 更新:使我理解这一点的参考文档-https: //developer.spotify.com/docs/apps/api/1.0/api-models-reference.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.