3

I am trying to update my Spotify remote control app that is currently using the legacy API to use the new 1.x API. Is it possible using the 1.x API to access information about the currently playing track? models.player.track does not seem to exist anymore (though it's in the documentation).

For the curious, I am using this for my app running in Spotify Desktop which uses websockets to talk with a Python server, which then provides a web interface for phones and tablets to remotely control the instance of Spotify running on the desktop. This works great using the legacy API and I can control playback and get the now playing info from any connected remote. I assume this app is going to stop working at some point soon since Spotify says they are retiring the legacy API. (Unless my assumption that the app will stop working is wrong, then never mind).

Thanks.

4

1 回答 1

1

可以通过加载track.Player

你会做这样的事情:

require(['$api/models'], function(models) {

    function printStatus(track) {
        if (track === null) {
            console.log('No track currently playing');
        } else {
            console.log('Now playing: ' + track.name);
        }
    }

    // update on load
    models.player.load('track').done(function(p) {
        printStatus(p.track);
    });

    // update on change
    models.player.addEventListener('change', function(p) {
        printStatus(p.data.track);
    });
});

您在Tutorial App中有一个名为Get the current playing track的工作示例。

于 2014-03-14T07:31:54.503 回答