29 сентября 2014 г.

SoundCloud Playlist Shuffle

Виджет для рандомизации очереди выполнения трэков виджета SoundCloud: https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/playlists/52259130

// via http://stackoverflow.com/a/6274381
//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/array/shuffle [v1.0]

require(['lib/play-manager'], function (a) {
    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();
    if (p) {
        a.pause(c);
    }
});

Источник