title: SoundCloud Api redirect confusion and Audio Api Streams
body: <p>I am attempting to make a request to the SoundCloud API. Then when I get the response I set the stream_url as the source of an &lt; audio > element. </p>
  
  <p>This works: </p>
  
  <p><a href="http://matthiasdv.org/beta/" rel="nofollow">http://matthiasdv.org/beta/</a>     </p>
  
  <p>But not always... When you search for 'Bonobo' for example, you can play the first few tracks without any issue. But when you try to play 'London Grammar - Hey Now (Bonobo remix)' - the 7th result - it won't play. It throws no errors whatsoever. </p>
  
  <p>I've been tinkering around with Chrome's webdev-tools and under the network tab I see the requests being made. I found that tracks that DO play have a short Request Url, like this:</p>
  
  <pre><code>https://ec-media.sndcdn.com/vR5ukuOzyLbw.128.mp3?f10880d39085a94a0418a7ef69b03d522cd6dfee9399eeb9a522029f6bfab939b9ae57af14bba24e44e1542924c205ad28a52352010cd0e7dd461e9243ab54dc0f0bba897d
  </code></pre>
  
  <p>And the ones that don't look like this: </p>
  
  <pre><code>https://cf-media.sndcdn.com/8PCswwlkswOd.128.mp3?Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiKjovL2NmLW1lZGlhLnNuZGNkbi5jb20vOFBDc3d3bGtzd09kLjEyOC5tcDMiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE0MzM0Mjc2MDN9fX1dfQ__&amp;Signature=cD-XVhnvQnIATkfrBDDVy0Q7996C8DymwxRLwBBduab0~L0MynF1ftcMky~21T8Q-gCZ2~dMK8dz7uVxvJTIJgXPxEZvhNtbvescMK6iFMg-xSAty-4OhJYjrIZJ2j8NE4uNA4Ml7MWbWcQw4KtUtpZitOQuguS3DPFDII3VF-dvzb2L~xG-G8Uu3uOnI1WhnAAfhf1QWMO7swwB89HtcCiuVBmfluG28ELrJEq-au8mqIMB3sLTno6nUuTtpHXR2ayXBsYcYLLJVXa3Ul8p1rhLS5XWHKWXY8xug4jwey27~C5PVAomK6Z5lJx-mz-0zYs4riUYtl0zACbZ1OfwTQ__&amp;Key-Pair-Id=APKAJAGZ7VMH2PFPW6UQ
  </code></pre>
  
  <p>Now at first glance I figured it was an encoding issue, but wrapping a quick encodeURI() around the ajax url did not work. </p>
  
  <p>Furthermore I do not understand where these urls come from. In my code I am directing my ajax request towards, for example:</p>
  
  <pre><code>https://api.soundcloud.com/tracks/140326936/stream?client_id=5c6ceaa17461a1c79d503b345a26a54e
  </code></pre>
  
  <p>Thus, the request url in the GET request (as found under 'network' in Chrome's webdev tools) makes no sense to me. Is SoundCloud redirecting get requests to a CDN-host? One more thing I've noticed is that each time TWO requests are fired instead of one. The first one is always canceled and contains a 'Provisional headers are shown' warning. I believe this is because I am setting crossOrigin = "anonymous", otherwise certain browsers would not load the content. </p>
  
  <p>What I guess may cause the problem is that when the url is set as the src attribute of the  element an evenListener is fired in the dancer.js library, which handles the Audio Api and the playback (<a href="https://github.com/jsantell/dancer.js/" rel="nofollow">https://github.com/jsantell/dancer.js/</a>). It may be that encodeURI() is required somewhere in the library. </p>
  
  <p>I decided to ask the question anyhow because I don't understand how the Request Urls's above are formed and why two, instead of one, requests are being fired and why the first is always cancelled. </p>
  
  <p>Any hints which my solve the playback issue are more than welcome too...  </p>