Question

Is there a way to disable next / previous track controls in the player with the new API, like Soundrop does?

I have come across such questions, there are a couple of suggestions like playing a single track or playing a context with only one track in it, or using setContextCanSkipPrev methods on the player, but none work for the new API. I need a solution for the API version 1.0.0

Was it helpful?

Solution

You need to create a temporary playlist with a single track and use the enforceRules function:

require(['$api/models'], function(models) {
  var tempName = 'temp' + (new Date()).getTime();
  models.Playlist.createTemporary(tempName).done(function(playlist) {
    playlist.enforceRules('stream');
    playlist.load("tracks").done(function(loadedPlaylist) {
      var track = models.Track.fromURI('spotify:track:7B1Dl3tXqySkB8OPEwVvSu');
      loadedPlaylist.tracks.add(track);
      models.player.playContext(loadedPlaylist, 0);
    });
  });
});

At the moment, it seems the documentation for the API is missing the description of this function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top