Type in your question below and we'll check to see what answers we can find...
Loading article...
Submitting...
If you couldn't find any answers in the previous step then we need to post your question in the community and wait for someone to respond. You'll be notified when that happens.
Simply add some detail to your question and refine the title if needed, choose the relevant category, then post.
Before we can post your question we need you to quickly make an account (or sign in if you already have one).
Don't worry - it's quick and painless! Just click below, and once you're logged in we'll bring you right back here and post your question. We'll remember what you've already typed in so you won't have to do it again.
Im bring to use the web api to play songs (one by one - not playlist)
and I get the following at the html.
Hi @Hubo,
Thanks for your response !
First of all ill mention that this only occurs on Safari.
I use the Web API to play tracks by their ids.
I'm using a code that is based on the docs.
var accessToken //Being updated every 45 minuts with a refresh_token request
window.onSpotifyWebPlaybackSDKReady = () => { ...
player = new Spotify.Player({
name: 'Votify',
getOAuthToken: cb => { cb(accessToken); }
});
listeners ...
}
Function loadTrack(currentTrack) {
//Fetches the track from the database...
if (player) {
playOnSpotify({
spotify_uri: currentTrack.uri,
playerInstance: player
});
}
and the playOnSpotify is:
const playOnSpotify = ({
spotify_uri,
playerInstance: {
_options: {
getOAuthToken,
device_Id
}
}
}) => {
console.log('playOnSpot ==>' + spotify_uri + ', deviceId =>>> ' + deviceId)
getOAuthToken(access_token => {
console.log('getOAuthToken ==>' + access_token)
fetch(`https://api.spotify.com/v1/me/player/play?device_id=${deviceId}`, {
method: 'PUT',
body: JSON.stringify({ uris: [spotify_uri] }),
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${access_token}`
},
})
});
};
I see this on Mac / Safari too. I almost never see it on Chrome. Steps to reproduce fairly reliably here:
- in Safari desktop or mobile initialize the web playback SDK and start a song per the docs
- See player_state_changed events as expected
- on Spotify Desktop see that a song is playing in the web playback device and advance the song position towards the end of the track
- Get `Unhandled Promise Rejection: TypeError: Cannot add negative msPlayed value: -5`
- Don't see any more player_state_changed events as expected
- Playing a new track through the web SDK also gives the TypeError
To clarify, you don't have to advance the track position in Spotify Desktop, it's just that the error happens at the end of a track so this is a faster way to trigger it.
I can reproduce the same error here on Mac/Safari 15.2 and iOS 15.1/Safari (Chrome works flawlessly). I built a simple album player, and when the tracks position reaches its end, the unhandled promise rejection pops up (not always, but most of the time). The source of this error is to be found in the file https://sdk.scdn.co/embedded/index.js on line 9819/9820. Maybe the solution for the Spotify developers would be as simple as changing line 9820 to e = 0; ? 🤔
I see this on Mac 12.0.1 / Firefox Dev Edition 96.0b10 (64-bit) too.
Seems to occur about 1 of 5 times that I call the `seek` method of the player.
I am also seeing this error on iOS & MacOS Safari when the current track finishes and you send a request to play the next track. I am playing tracks individually rather than from a playlist.
Is there a solution to this?
I'm also seeing this issue on the latest macOS with Safari.
Hey there you, Yeah, you! 😁 Welcome - we're glad you joined the Spotify Community! While you here, let's have a fun game and get…