如何避免针对Web音频API的CORS限制? [英] How can I avoid CORS restriction for web audio api?

查看:69
本文介绍了如何避免针对Web音频API的CORS限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为音频流创建一些可视化。但是,当我尝试使用 createMediaElementSource()函数访问原始音频数据时,会遇到CORS麻烦。

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.

是有没有办法避免这种限制,并从其他来源的流中获取原始音频数据?也许使用WebSockets?

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

推荐答案

有五种方法可以防止跨域检索:

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


  1. CORS标头-这是理想选择,但是您需要第三方服务器的配合

  2. JSONP-不是适用于流式传输内容,通常需要第三方服务器的合作

  3. iframe和窗口间通信-可能不适合流式传输内容,您需要第三方的协作,缔约方服务器

  4. 关闭浏览器保护-您需要在自定义模式下运行浏览器,并且不应将该浏览器用于其他任何用途

  5. 服务器端代理-相对较慢,但通常是唯一可行的选择

  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

这篇关于如何避免针对Web音频API的CORS限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆