I was wondering how to add a album cover on my spotify-app?
With this code I can reveal the album title, but how can I show the album cover!?
function updatePageWithAlbumName() {
var header = document.getElementById("album");
// This will be null if nothing is playing.
var playerTrackInfo = sp.trackPlayer.getNowPlayingTrack();
if (playerTrackInfo == null) {
header.innerText = "Geen album!";
} else {
var track = playerTrackInfo.track;
header.innerText = track.album.name;
}
}
Please don't use any of the sp.
APIs - they're private and going away soon.
The public API is documented here: http://developer.spotify.com/download/spotify-apps-api/preview/reference/
You can show an album cover like this:
<img src="[cover URI]">
Edit: To get the cover URI of the current track:
var sp = getSpotifyApi(1);
var models = sp.require('sp://import/scripts/api/models');
var currentTrackCoverUri = models.player.track.album.cover;
I would like to point out that the property seems to be called "image" and not "cover".
So the snippet provided by iKenndac would be rewritten as
var sp = getSpotifyApi(1);
var models = sp.require('sp://import/scripts/api/models');
var currentTrackCoverUri = models.player.track.album.image;
Not sure if this is dependant on my Spotify version, I'm running 0.8.10.3.g07d01e81.
The UX guidelines requires you to present an album cover with playability when appropriate. This can be done with the solution from another topic: Views.player album cover