Spotify App API: Play specific track from album

淺唱寂寞╮ 提交于 2019-12-04 06:44:10

问题


Trying to play a specific track from an album with the player view. It works all good when using

player.play(objTrack, objTrack.album);

But I don't want the song to autoplay, so I'm using:

player.track = objTrack;
player.context = objTrack.album;

But when I do so, either it won't work at all or it will start playing the first track of the album regardless which track I set.

How can I make this work? :/ Thanks.


This does not do the trick either. I'm currently trying this method:

var album = m.Album.fromURI('spotify:album:7Kmmw7Z5D2UD5MVwdm10sT', function(album) {
   var player = new v.Player();
   player.track = album.get(3);
   player.context = album;
   document.body.appendChild(player.node);
});

But this will not fetch and play track number 3, it will play the first track of the album. And if the album only contains 1 track, it will crash. Any ideas?


回答1:


If you have the current track number I suppose you got it from a track object. Here is my way:

// trackObj <- The track object

var album = m.Album.fromURI('spotify:album:7Kmmw7Z5D2UD5MVwdm10sT', function(album) {
    var player = new v.Player();
    player.track = trackObj;
    album.get = function() {
        return trackObj;
    }
    player.context = album;
    document.body.appendChild(player.node);
});


来源:https://stackoverflow.com/questions/8416256/spotify-app-api-play-specific-track-from-album

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