Question

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?

Was it helpful?

Solution

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);
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top