Spotify apps: Listen for "Subscribe" event on a Playlist

358 views Asked by At

Is there any way to be notified if a user subscribe/unsubscribe to a playlist?

Ideally I want to be able to do something like this:

var sp = getSpotifyApi(1);
var models = sp.require('sp://import/scripts/api/models');
var playlist = models.Playlist.fromURI("spotify:user:spotify:playlist:3Yrvm5lBgnhzTYTXx2l55x");

playlist.observe(models.EVENT.SUBSCRIBE, function() {  // <-- This "SUBSCRIBE" event don't exist...
    console.log("Playlist was subscribed/unsubscribed!");
});

/* later in code */

playlist.subscribed = true; // Outputs: Playlist was subscribed/unsubscribed!

Is there any pattern that could accomplish such thing?

Ultimately, I want to change the gui state of several different objects depending if the playlist is subscribed or not during runtime. But these objects don't know about each other, being the only common denominator a Spotify playlist object created from the same URI.

1

There are 1 answers

1
iKenndac On

Change models.EVENT.SUBSCRIBE to models.EVENT.CHANGE and you'll be set. A few other things trigger this as well, so make sure you make a check before updating UI.