How to prevent context usage in Spotify App to turn off skip controls

I’m working on a Spotify app and need to control which tracks get played. I want to disable the skip forward and skip backward buttons so users can’t navigate away from the current song.

From what I understand, the solution involves playing tracks without providing any context to the player. I tried this approach but the skip buttons remain active. It looks like Spotify is still using my favorites playlist as the default context.

Here’s my current implementation:

var spotifyAPI = getSpotifyApi(1);
var apiModels = spotifyAPI.require('sp://import/scripts/api/models');
var audioPlayer = apiModels.player;
var favoritesList = apiModels.library.starredPlaylist;

exports.initialize = initialize;

function initialize() {
    var titleElement = document.getElementById("title");
    var randomIndex = Math.floor(Math.random()*favoritesList.length)
    var selectedTrack = favoritesList.get(randomIndex);

    if (favoritesList == null) {
        titleElement.innerText = "favorites not loaded";
    } else if (selectedTrack == null) {
        titleElement.innerHTML = "failed to get track from favorites";
    } else {
        titleElement.innerHTML = "favorites " + randomIndex + "/" + favoritesList.length + " : " + selectedTrack.name;
    }

    audioPlayer.play(selectedTrack, null);
}

I also attempted to load tracks using direct URIs without accessing the favorites playlist:

function initialize() {
    var titleElement = document.getElementById("title");
    var audioPlayer = apiModels.player;

    apiModels.Track.fromURI("spotify:track:4uLU6hMCjMI75M1A2tKUQC", function(isolatedTrack) {
        console.log("Track retrieved", isolatedTrack.name);
        audioPlayer.play(isolatedTrack, null);
        titleElement.innerHTML = "now playing: " + isolatedTrack.name;
    }); 
}

Interestingly, the skip buttons aren’t completely disabled. When I click previous it restarts the current track, and clicking next moves to an empty state where all controls become inactive. Has anyone found a working solution for this?

This happens because Spotify’s context management automatically assigns a playback context even when you pass null. The skip buttons showing up is actually expected behavior - Spotify keeps the context internally to avoid UI issues. I’ve run into this developing Spotify apps, and you can’t just avoid the context - you need to override it completely. Wrap your track in a temporary playlist object with only that one track before sending it to the player. Make sure there’s nothing else in the playlist for the skip controls to grab onto. You could also intercept the skip button events with the player’s event listeners and block their default behavior. That gives you more control but you’ll need to handle edge cases like keyboard shortcuts or external controls.

had the same prob! what worked for me was making a temp playlist with just one track. skip buttons still show but they don’t do nuthin since there’s no other song to go to. i used audioPlayer.play(track, tempPlaylist) and it worked perfectly!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.