title: How do I make an audio player with the Spotify Web API?
body: <p>I was trying to make an audio player by starting with a play button. In my HTMl code i made a button:</p>
  
  <pre><code>&lt;a href="#" id="play" alt="animate" class="btnstyle"&gt;Play&lt;/a&gt;
  </code></pre>
  
  <p>Then I used this code to make it play a song, but it doesnt seem to work.</p>
  
  <pre><code>document.getElementById('play').addEventListener('click', function() {
    $.ajax({
      url: 'https://api.spotify.com/v1/me/player/play',
      type: 'PUT',
      headers: {
        'Authorization': 'Bearer ' + access_token
      },
      dataType: "json",
      contentType: "application/json",
      data: JSON.stringify({
          "uris": ["spotify:track:"] + apiData.item.id,
          "position_ms": apiData.progress_ms
      })
    });
  }); 
  </code></pre>
  
  <p>apiData.item.id refers to the id of the currently playing track
  apiData.progress_ms refers to the progress in milliseconds of currently playing track.</p>
  
  <p>When I run my code and click on the play button, nothing happens. I don't know what I did wrong.</p>
  
  <p>But I tried making a pause button by first making a button with an id called 'pause'. Then I did the following:</p>
  
  <pre><code>document.getElementById('pause').addEventListener('click', function() {
    $.ajax({
      url: 'https://api.spotify.com/v1/me/player/pause',
      type: 'PUT',
      headers: {
        'Authorization': 'Bearer ' + access_token
      },
      dataType: "json",
      contentType: "application/json",
      data: JSON.stringify({
        "uris": ["spotify:track:"] + apiData.item.id,
        "position_ms": apiData.progress_ms
      })
    });
  });
  </code></pre>
  
  <p>This is actually working! But I don't understand why the play button doesn't work and the pause button does. 
  Here is the documentation I used for both buttons:
  <a href="https://developer.spotify.com/documentation/web-api/reference/player/start-a-users-playback/" rel="nofollow noreferrer">https://developer.spotify.com/documentation/web-api/reference/player/start-a-users-playback/</a>
  <a href="https://developer.spotify.com/documentation/web-api/reference/player/pause-a-users-playback/" rel="nofollow noreferrer">https://developer.spotify.com/documentation/web-api/reference/player/pause-a-users-playback/</a></p>
  
  <p>For the play button I got this error in the console log:
  <a href="https://i.stack.imgur.com/tqTtP.jpg" rel="nofollow noreferrer">error 400</a></p>
  
  <p>Can somebody help me out?</p>