Question

The new Spotify Apps Javascript API contains a number of objects like Album, Library, Link etc. But how do you actually instantiate and use any of them in your app? I've looked at the tutorial app but all that is used there is the trackPlayer object which isn't documented as far as I can tell. The answer to this question suggests looking in the in the app bundle at Spotify.app/Contents/Resources/cef_views. However, I can't seem to find this on my Mac and there seems to be no corresponding folder on Windows.

Any help would be greatly appreciated.

Was it helpful?

Solution

First, to answer your second question about where to find the folder (I also posted this as a comment in my own original post):


In Windows the folder is located as a .zip file (resources.zip) in the data folder next so Spotify.exe. In my case this is

C:\Users\buchetics\AppData\Roaming\Spotify\Data\resources.zip

On the Mac, you need to right click Spotify.app and select Show Package Content (or something like that), then you can navigate to the folder inside the bundle.


Ok, now to your original question. You can get the API objects like this:

window.Models = sp.require("sp://import/scripts/api/models");
window.Views = sp.require("sp://import/scripts/api/views");

Then, you can use all the methods and properties as described in the API reference (which is still not very good). For example:

window.CurrentPlaylist = new Models.Playlist();
var track = Models.Track.fromURI("spotify:track:4n6AGL10M8fbm8oHxhK16j");
CurrentPlaylist.add(track);

And so on. The Models API is quite easy to use and the Views object can be used to render a track list similar to the regular Spotify lists. For other API calls, such as getting the current playing track, you need to use the core API which is returend by var sp = getSpotifyApi(1);. However, there is no documentation for this yet and the best advice is to look at the code found in cef_views or use the Inspector on the available apps to find useful code pieces (not all of the apps expose their code in a way to easily look at it, but some do, such as the "We are Hunted" or "Songkicks" app).

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