3

Soundcloud api should support cors as I read in documentation (http://developers.soundcloud.com/docs/api/guide#crossdomain).

But I think this is not the case:

XMLHttpRequest cannot load http://ec-media.soundcloud.com/fxguEjG4ax6B.128.mp3?longurldata... Cannot make any requests from null.

What am I doing wrong? I'm trying to play stream with aurora.js + mp3.js.

ewooycom
  • 2,651
  • 5
  • 30
  • 52

2 Answers2

2

Supporting CORS isn't an all-or-nothing, the server end chooses to support specific origins (and headers, and methods).

In your case, you appear to be making the call from a local file (origin null), e.g. an HTML document you've loaded via double-clicking from the file system or similar. Apparently they don't allow that.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • Oh thanks for fast reply, I'll move code to VPS with domain and I'll try again tomorrow. Btw what am I doing right now is: I have nginx to handle domain s.co, and modified /etc/hosts so that s.co points to 127.0.0.1, so origin should not be null, right? – ewooycom Feb 26 '13 at 21:49
  • 1
    @user1188570: It shouldn't be `null` ***if*** you're loading the page from `http://s.co`, no. – T.J. Crowder Feb 26 '13 at 21:50
1

Unfortunately, at the moment, the CORS headers aren't enabled on the mp3 files that are delivered from the CDN (ec-media subdomain). You'd need to use a proxy if you need to request these files via XHR.

CORS headers are enabled on the JSON data returned from the API, but not the mp3s.

If you are trying to use Web Audio API you could use mediaElementSource and load the mp3 via setting src property of the audio to be used as “media source” as described here.

Community
  • 1
  • 1
Misha Reyzlin
  • 13,736
  • 4
  • 54
  • 63
  • well, It seems like XHRHttpRequest works on mp3's sometimes. I created a demo www.zya.cc/scsampler which works on Chrome. but does not work on all the links. even when they are downloadable. What would be the reason? – zya Jan 23 '14 at 17:03
  • @gryzzly this [doesn't work on Firefox or Safari](http://stackoverflow.com/a/23202652/1397319) and will [no longer work on Chrome in the near future](https://stackoverflow.com/questions/28984883/cannot-analyse-soundclouds-streaming-audio-because-of-the-lack-of-cors-policy). – idbehold Mar 12 '15 at 21:33