Skip to content

Instantly share code, notes, and snippets.

@mager
Created February 10, 2012 18:22
Show Gist options
  • Save mager/1791443 to your computer and use it in GitHub Desktop.
Save mager/1791443 to your computer and use it in GitHub Desktop.
Spotify Apps API - Get the currently playing track (JS)
/* Instantiate the global sp object; include models & views */
var sp = getSpotifyApi(1);
var models = sp.require("sp://import/scripts/api/models");
// Get the track that is currently playing
var currentTrack = models.player.track;
// If nothing currently playing
if (currentTrack == null) {
$('#now-playing').append('No track currently playing');
} else {
var track = currentTrack;
var artist = track.artists[0].name;
$('#now-playing').append("Now playing: " + track, artist);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment