Skip to content

Randomizing the Playlist

DubbyTT edited this page Nov 3, 2012 · 6 revisions

You can randomize your playlist by doing the following:

bot.playlistAll(function(playlist) {
  console.log("Playlist length: " + playlist.list.length);
  var i = 0;
  var reorder = setInterval(function() {
    if (i <= playlist.list.length) {
      var nextId = Math.ceil(Math.random() * playlist.list.length);
      bot.playlistReorder(i, nextId);
      console.log("Song " + i + " changed.");
      i++;
    } else {
      clearInterval(reorder);
      console.log("Reorder Ended");
      bot.speak("Reorder completed.");
    }
  }, 1000);
});
Clone this wiki locally