Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

Hello ửolasdfasdAtlas

Reply

Hello ửolasdfasdAtlas

<script src="https://sdk.scdn.co/spotify-player.js"></script>

You are then required to define a window.onSpotifyWebPlaybackSDKReady method immediately. This will be executed once the Web Playback SDK has successfully loaded and the Spotify.Player is available to load the SDK.

<script>
window.onSpotifyWebPlaybackSDKReady = () => {
  // You can now initialize Spotify.Player and use the SDK
};
</script>

Playing a Spotify URI

The Web Playback SDK is only designed to create a local Connect device in your browser. The Web API is for additional actions such as search or playing a Spotify URI on any of a user’s Connect devices.

Here’s a JavaScript code example of how to play a Spotify URI using the Web API:

const play = ({
  spotify_uri,
  playerInstance: {
    _options: {
      getOAuthToken
    }
  }
}) => {
  getOAuthToken(access_token => {
    fetch(`https://api.spotify.com/v1/me/player/play?device_id=${id}`, {
      method: 'PUT',
      body: JSON.stringify({ uris: [spotify_uri] }),
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${access_token}`
      },
    });
  });
};

play({
  playerInstance: new Spotify.Player({ name: "..." }),
  spotify_uri: 'spotify:track:7xGfFoTpQ2E7fRF5lN10tr',
});
0 Replies

Suggested posts

Let's introduce ourselves!

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…

ModeratorStaff / Moderator/ 4 years ago  in Social & Random