Created
March 19, 2012 12:54
-
-
Save javierarce/2111027 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Configuration and API URL | |
var username = "YOUR_USERNAME"; | |
var api_key = "YOUR_API_KEY"; // To get an API key go to http://www.last.fm/api/account | |
var url = "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=" + username + "&api_key=" + api_key + "&limit=1&format=json&callback=lastTrackCallback"; | |
// API call | |
function getCurrentTrack() { | |
$.ajax({ | |
url: url, | |
data: null, | |
success: showCurrentTrack, | |
dataType: "jsonp" | |
}); | |
} | |
// Returns the title of the song and the name of the album you're currently listening to | |
function showCurrentTrack(data) { | |
var tracks = data.recenttracks.track; | |
track = tracks[0]; | |
if (track && "@attr" in track && track["@attr"].nowplaying == "true") { | |
$("#listening .track").html('<img src="http://assets.javierarce.com/eq.gif" width="12px" height="12px" />' + track.name + ' by ' + '<strong>' + track.artist["#text"] + '</strong>'); | |
$("#listening").addClass("active"); | |
$("#listening .track").delay(250).fadeIn(250); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment