【问题标题】:Web Audio API and <audio> tagWeb Audio API 和 <audio> 标签
【发布时间】:2015-03-27 21:00:51
【问题描述】:

我在让 html5 标记与 Web Audio API .createMediaElementSource() 方法配合使用时遇到问题。请参阅下面的 jsFiddle/代码。如果您知道这里出了什么问题,我们将不胜感激。

我读到 here 说这是 FireFox 中的一个问题,但是 a) 我在 Chrome 中工作,b) 如果 .mp3 与 .html 位于同一文件夹中,则它不起作用。

这里的最终目标是使用创建一个站点来过滤来自 SoundCloud API 的曲目,如果有人有任何建议的话。

http://jsfiddle.net/6v9jkcn1/

js:

$(function(){
  //create audio context
  var context = new AudioContext();

  //set variable pointing at the audiotag
  var audio = document.getElementById('player');

  //declare source that will become the media element source, create gain and filter, and connect them
  var source;
  var gain = context.createGain();
  var filter = context.createBiquadFilter();

  //routing
  gain.connect(filter);
  filter.connect(context.destination);
  filter.frequency.value = 220;

  //when the audio has sufficiently loaded, create media element source and connect it to the gain
  audio.oncanplaythrough = function(){

        source = context.createMediaElementSource(audio);

        source.connect(gain);
      };
    });

HTML:

<audio id='player' src='http://develiot.com/eqsoundcloud/EttaAnything.mp3' controls></audio>

【问题讨论】:

    标签: html5-audio web-audio-api


    【解决方案1】:

    Chrome 也遵循同源策略,除非您在服务器上启用了 CORS。

    【讨论】:

    • 啊 - 我是这么认为的 - 但是,即使文件在同一个域中,这也不起作用(不确定如何在 stackoverflow 中建模
    • 当你说它们在同一个域中时,它们是否都在本地文件中,加载了“file://”URL?本地文件永远不能与 CORS 一起使用。一切都必须通过 HTTP 加载。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2015-11-24
    • 2021-01-03
    • 1970-01-01
    • 2011-12-02
    • 2015-11-09
    • 2015-10-10
    相关资源
    最近更新 更多