is it possible, from an spotify application, to hide or overwrite the "now playing" pannel (the cover and artist name/track name of the playing track) ?
Thx, for your help.
I try to modify the Album object or the Track object provided to the player but it don't work :
models.Album.fromURI("spotify:album:3ty039P7JO7bTcWtWi1AP6", function(a) {
var player = new v.Player();
var track = a.get(0);
//a.artist = "TOTO";
//a.cover = "sp://import/img/placeholders/300-album.png";
//track.image = 'sp://import/img/placeholders/300-album.png';
track.name = "Test";
player.play(track,a);
});
This is not possible in the current API, mainly because we don't want people overwriting now playing information with adverts and stuff.
Related
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...
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);
}
}
});
});
});
});
On my spotify app, if I click on player to play track, the track is highlighted in the list-view. But when I click on the next button of spotify the next track in the list-view is not highlighted, even when it is being played...the highlighting is totally lost. And I do not know how to do it. It works if I just reload the app or I go on next tab. Can anyone guide me as how to fix this? Thanks in advance :-)
models.Track.fromURI(track, function(track) {
models.Album.fromURI(track.album.uri, function(album) {
var pl = new views.Player();
pl.context = album;
document.getElementById('imag').appendChild ( pl.node );
var tracklist = new views.List(album);
tracklist.node.classList.add("sp-list");
$("#song1").append(tracklist.node);
Your code should work without any problems, since you are using the same context for both
Player and List views. In fact, I have tested it and it works for me (note that I have added a couple of missing lines):
var sp = getSpotifyApi(),
models = sp.require("$api/models"),
views = sp.require("$api/views"),
track = "spotify:track:6G0RXhQJGDnjgUdbQfBZRk";
models.Track.fromURI(track, function(track) {
models.Album.fromURI(track.album.uri, function(album) {
var pl = new views.Player();
pl.context = album;
document.getElementById("imag").appendChild(pl.node);
var tracklist = new views.List(album);
tracklist.node.classList.add("sp-list");
document.getElementById("song1").appendChild(tracklist.node);
});
});
Point 16. of the app design guidelines describes how links to artists, tracks or albums should look like but I can't find a place that tells how one can create such a link with HTML/CSS and/or Javascript.
Horse Of a Different Color
The client will be smart enough to do the right thing. You can get these URIs from Track, Artist, Album and Playlist objects in the API.
The solution is so simple... It's the player view we're talking about here. See this example:
var sp = getSpotifyApi(1);
var models = sp.require("sp://import/scripts/api/models");
var views = sp.require("sp://import/scripts/api/views");
$(document).ready(function()
{
new models.Album.fromURI("spotify:album:7auFBtmCGcTn7ElPelMLPn", function(ctx)
{
var player = new views.Player();
player.context = ctx;
$("#my-album-player").append(player.node);
});
});
Thanks to ikenndac who sent me on the right track!
I am having trouble removing the time field from a playlist in the Spotify App. I only want to display Song title, Artist and Album. Any help on this topic would be truly helpful.
You can specify which track attributes to display using the List object. An example is here: http://deceptacle.com/2011/12/26/spotify-app-api-some-things/
var list = new views.List(playlist, function (track) {
return new views.Track(track, views.Track.FIELD.NAME |
views.Track.FIELD.ARTIST |
views.Track.FIELD.ALBUM);
});
$("#playlist").append(list.node);
Update
More fleshed out example:
var pl = m.Playlist.fromURI("spotify:user:rhino_records:playlist:6sSFeKDgDxVR81YqNOuPf2");
var list = new v.List(pl, function (track) {
return new views.Track(track, views.Track.FIELD.NAME |
views.Track.FIELD.ARTIST |
views.Track.FIELD.ALBUM);
});
document.body.appendChild(list.node);
m is the models namespace, v is the views namespace. For some reason, it's not quite working for me. It seems like the observer methods aren't being called at the moment. Seems to be a spotify backend thing though. It seems to get called eventually after some prodding
I'm making a prototype Spotify Application, and I am stuck on the last part of code.
I have a list of albums URI, and want to display an album with cover and link to it. So I parse the list, create an album object, and push the HTML corresponding to what I want.
It look like this:
for(var i = data.length; i--; ) {
var cd = models.Album.fromURI(data[i].uri);
var cover = $(document.createElement('div')).attr('id', 'player-image');
cover.append($(document.createElement('a')).attr('href', data[i].uri));
var img = new ui.SPImage(cd.cover ? cd.cover : "sp://import/img/placeholders/300-album.png");
cover.children().append(img.node);
$("#discs").append(cover);
}
I don't understand why cd.cover is always empty.
Looks like the documentation is incorrect. Instead of using the cover property use image from the track or album object.