Question

For my app I need to shuffle a collection before turning it into a snapshot to use later. According to the documentation the shuffle() method returns a new collection with its tracks randomized, so I should be able to call the snapshot() method immediately (since it doesn't return a Promise, like snapshot() does).

Here's my test code, which works as expected without the shuffle method. However, it shows nothing in the console with it added.

playlist.load('tracks').done(function(tracks) {

  // Works when shuffle() is removed                    
  playlist.tracks.shuffle().snapshot()
    .done(

      function( snapshot ) {
        console.log( snapshot );

        for (var i = 0; i < snapshot.length; i++) {
          var track = snapshot.get(i);   
          console.log(track.name);
        }
      }
    );
});

Any ideas?

Was it helpful?

Solution

Looks like some ambitious documentation - shuffle doesn't seem to be implemented. When I ran this:

require(['$api/models'], function (models) {
    playlist = models.Playlist.fromURI(localStorage.album_radio_playlist);

    playlist.load('tracks').done(function (tracks) {
        console.log(tracks);
        // Works when shuffle() is removed                    
        playlist.tracks.shuffle().snapshot()
          .done(

            function (snapshot) {
                console.log(snapshot);

                for (var i = 0; i < snapshot.length; i++) {
                    var track = snapshot.get(i);
                    console.log(track.name);
                }
            }
          ).fail(function (blah, err) { console.log("failed to shuffle " + err); });
    });
});

I got this output

14:46:05.156 A [shell/lists/ItemListFactory.h:239] Check failed: Not implemented!     
14:46:05.167 I [sp://67456db3aaa5a1c25a619472cdb2cbc3f52da3ed.album-radio/js/albumradio.js:684] failed to shuffle undefined
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top