Skip to content

Instantly share code, notes, and snippets.

@rctay
Created March 28, 2014 10:01
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rctay/9829266 to your computer and use it in GitHub Desktop.
Save rctay/9829266 to your computer and use it in GitHub Desktop.
shuffle/randomize playlist/set tracks in Soundcloud Widget eg. https://w.soundcloud.com/player/?url=http://api.soundcloud.com/users/1539950/favorites
require(["lib/play-manager"], function(a) {
// via http://stackoverflow.com/a/6274381
//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/array/shuffle [v1.0]
function shuf(o) { for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); }
shuf(a.source.models);
var c = a.getCurrentSound(), p = c ? c.isPaused() : false;
a.playNext(); a.playPrev(); // poor man's refresh of current playing song
if (p) a.pause(c); // preserve first-run state
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment