title: With SoundCloud default audio widget can you set it to shuffle from JavaScript?
body: <p>I am using the default SoundCloud audio widget to play a playlist and would like the songs to play in a random order.  I am using the SoundCloud JavaScript SDK oEmbed object (the iframe version).</p>
  
  <pre><code>&lt;script src="//connect.soundcloud.com/sdk.js"&gt;&lt;/script&gt;  
  
  SC.oEmbed("//soundcloud.com/buzzinfly",  { 
    auto_play: true,   
    start_track: random_start_track,  
    iframe: true,  
    maxwidth: 480,  
    enable_api: true,  
    randomize: true 
   },  
   document.getElementById("soundcloud_player"));
  </code></pre>
  
  <p>The documentation doesn't mention any randomize or shuffle attribute, but other undocumented attributes like start_track are supported with oembed.</p>
  
  <pre><code>//developers.soundcloud.com/docs/oembed#parameters
  //developers.soundcloud.com/docs/widget
  </code></pre>
  
  <p>Does any one know if there is an attribute to shuffle the song order in the default audio widget?</p>
  
  <p>If not, is there is a way to capture events from the default SoundCloud widget, so I can play a random song after a song finish event?   Like you can with the custom player.</p>
  
  <p>//developers.soundcloud.com/docs/custom-player#events</p>
  
  <pre><code>$(document).bind('onPlayerTrackSwitch.scPlayer', function(event, track){  
    // goto random track   
  });  
  </code></pre>
  
  <p>Thanks</p>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>Here is code am I using after getting gryzzly's help.</p>
  
  <p>The next button works great.  I can skip thru random songs.  Unfortunately, when a track finishes playing, I hear the audio of two songs: the next song in the playlist and the random track that is skipped to in the FINISH event.  </p>
  
  <pre><code>var widget = null;
  var song_indexes = new Array();
  var current_index = 0;
  
  $(function() {
      var iframe = document.querySelector('#soundcloud_player iframe');
      widget = SC.Widget(iframe);        
      widget.bind(SC.Widget.Events.READY, function() {
          widget.unbind(SC.Widget.Events.FINISH);
          widget.bind(SC.Widget.Events.FINISH, function() {        
              play_next_shuffled_song();
          });
  
          widget.getSounds(function(sounds) {
              create_shuffled_indexes(sounds.length);
              play_next_shuffled_song();
          });               
      });
      $("#button_sc_next").on("click", play_next_shuffled_song);
  });
  
  function play_next_shuffled_song() {
      current_index++;
      if (current_index &gt;= song_indexes.length) {
          current_index = 0;
      }  
      var track_number = song_indexes[current_index];
      widget.skip(track_number);
  }
  
  function create_shuffled_indexes (num_songs) {
      for (var i=0;i&lt;num_songs;i++) {
          song_indexes.push(i);
      }
      song_indexes = shuffle(song_indexes);
  }
  
  //+ Jonas Raoni Soares Silva
  //@ http://jsfromhell.com/array/shuffle [v1.0]
  function shuffle(o){ //v1.0
      for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
      return o;
  };
  </code></pre>