5

I trying to create some visualization for audio-stream. But I run into CORS trouble when I try get access to raw audio data with createMediaElementSource() function.

Is there a way to avoid this restriction and get raw audio data from stream on other origins? Perhaps using WebSockets?

Alexey Nikiforov
  • 357
  • 1
  • 4
  • 14
  • 1
    Use a server-side proxy script to download and server the file. Host JS and proxy on the same server. – Mikko Ohtamaa Jun 02 '15 at 18:34
  • possible duplicate of [Ways to circumvent the same-origin policy](http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy) – Dave Jun 02 '15 at 21:49

1 Answers1

7

There are five ways to deal with the protections against cross-origin retrieval:

  1. CORS headers -- this is ideal, but you need the cooperation of the third-party server
  2. JSONP -- not appropriate for streaming content and you typically need the cooperation of the third-party server
  3. Iframes and inter-window communication -- probably not appropriate for streaming content and you need the cooperation of the third-party server
  4. Turning off browser protections -- you need to be running the browser in a custom mode, and you should not use that browser for anything else
  5. Server-side proxy -- comparatively slow but often the only feasible option
Michael Lorton
  • 43,060
  • 26
  • 103
  • 144
  • Could you explain what CORS headers to set? I have the same problem. However, the server is mine so I can easily modify the headers. I don't know what headers to set. Thank you :) – www139 Dec 23 '16 at 18:18
  • I've already tried that. It doesn't work for what I'm doing. It's ok. My situation is probably too complicated and beyond the scope of this question. I just asked a question and revealed more information http://stackoverflow.com/questions/41306459/cors-headers-for-accessing-a-file-on-another-domain – www139 Dec 23 '16 at 19:03