Play a single song

This snippet of code plays a hardcoded Spotify URI.

The Javascript

/* Instantiate the global sp object; include models & views */
var sp = getSpotifyApi(1);
var models = sp.require("sp://import/scripts/api/models");
var views = sp.require("sp://import/scripts/api/views");

/* Create an array of tracks from the user's library */
var track = models.Track.fromURI('spotify:track:7DJI0fg4dzBJk31sEmn6Zk');

/* Create a temporary playlist for the song */
var playlist = new models.Playlist();
playlist.add(track);
var playerView = new views.Player();
playerView.track = null; // Don't play the track right away
playerView.context = playlist;

/* Pass the player HTML code to the #player div */
$('#player').append(playerView.node);

The HTML

<div id="player"></div>

The CSS

<style> 
    @import url("sp://import/css/api.css");                               
    @import url('sp://import/css/eve.css');                               
    @import url('sp://import/css/player.css');                            
</style>

Live Example