Reputation: 4815
I'm building an app that is generating a temporary playlist of tracks. I am then attempting to create a "Start Radio" button for that temporary playlist.
The button is generated, but when I click it, the screen changes to radio, but doesn't play nor does it load any radio station.
My guess is that this is not supported, because if I create a regular playlist and do it, it does play the radio...
But I cannot find any information in the API that confirms or deny my guess.
Does any one know for certain if this is not supported?
I would really rather do this from a temp playlist than have to maintain a real one...
Upvotes: 0
Views: 312
Reputation: 3279
You are right. The Start Radio Button doesn't support temporary playlists. And, unfortunately, the documentation doesn't mention this.
It seems that the track data attached to the temporary playlist can't be passed to the Radio app, so the Radio app loads with no context information.
The only way to achieve this is, as you said, creating a persistent playlist and create a radio button for that. In order to not create a new playlist every time, you can also try to find the playlist you created previously in the user's library.
See this code snippet:
require(['$api/models', '$api/library#Library', '$views/buttons#StartRadioButton'],
function(models, Library, StartRadioButton) {
// create a temporary playlist with some tracks
var playlistName = 'Some name';
models.Playlist.create(playlistName).done(function(playlist) {
playlist.load('tracks').done(function(loadedPlaylist) {
var track1 = models.Track.fromURI('spotify:track:5EB60KIbYgL8nWrHoYbfv4');
var track2 = models.Track.fromURI('spotify:track:7GPuYTiBA5BloBnFaQBjbw');
loadedPlaylist.tracks.add(track1);
loadedPlaylist.tracks.add(track2);
// now we can add a button to start a radio base on the newly
// created playlist
var button = StartRadioButton.forPlaylist(loadedPlaylist);
document.body.appendChild(button.node);
// bonus: we can also search for the playlist in the user's library
// so we don't have to create a new one all the time.
// this will work as long as we can find the playlist we created by name
// (i.e. it hasn't been renamed).
var currentLibrary = Library.forCurrentUser();
console.log(currentLibrary);
currentLibrary.playlists.snapshot().done(function(p) {
for (var i = 0; i < p.length; i++) {
var playlistFromLibrary = p.get(i);
if (playlistFromLibrary && playlistFromLibrary.name == playlistName) {
var button = StartRadioButton.forPlaylist(playlistFromLibrary);
document.body.appendChild(button.node);
}
}
});
});
});
});
Upvotes: 1