I’m working on a Spotify app and I need to disable the skip forward and skip backward buttons. I want full control over which tracks get played.
I found some discussion about this online and it seems like the solution involves playing tracks without providing a context to the player. However when I try this approach, the navigation buttons stay active and Spotify treats my starred playlist as the current context.
Here’s my current implementation:
var spotifyAPI = getSpotifyApi(1);
var apiModels = spotifyAPI.require('sp://import/scripts/api/models');
var audioPlayer = apiModels.player;
var starredTracks = apiModels.library.starredPlaylist;
exports.initialize = initialize;
function initialize() {
var headerElement = document.getElementById("header");
var randomIndex = Math.floor(Math.random() * starredTracks.length);
var selectedTrack = starredTracks.get(randomIndex);
if (starredTracks == null) {
headerElement.innerText = "starred playlist not found";
} else if (selectedTrack == null) {
headerElement.innerHTML = "unable to retrieve track from starred";
} else {
headerElement.innerHTML = "playing " + randomIndex + "/" + starredTracks.length + " : " + selectedTrack.name;
}
audioPlayer.play(selectedTrack, null);
}
I also tried loading tracks directly by URI to avoid any playlist context:
function initialize() {
var headerElement = document.getElementById("header");
var audioPlayer = apiModels.player;
apiModels.Track.fromURI("spotify:track:4YfW3Z2MEvd71pv4J1rN3k", function(isolatedTrack) {
console.log("Track loaded successfully", isolatedTrack.name);
audioPlayer.play(isolatedTrack, null);
headerElement.innerHTML = "now playing: " + isolatedTrack.name;
});
}
The skip buttons appear disabled but clicking previous restarts the current track and clicking next goes to a “no track” state. Is there a proper way to completely disable track navigation in Spotify apps?