Showing a album cover

亡梦爱人 提交于 2020-01-06 08:42:03

问题


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;
}

}


回答1:


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;



回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/9474011/showing-a-album-cover

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!