Get the currently-playing track

Checks to see if the player is playing.

The Javascript

/* Instantiate the global sp object; include models */
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);
}

The HTML

<div id="now-playing"></div>

Live Example