【问题标题】:Connecting MediaElementAudioSourceNode to AudioContext.destination doesn't work将 MediaElementAudioSourceNode 连接到 AudioContext.destination 不起作用
【发布时间】:2015-04-26 19:50:39
【问题描述】:

Here's a fiddle to show the problem。基本上,每当调用AudioContext 对象的createMediaElementSource 方法时,音频元素的输出都会重新路由到返回的MediaElementAudioSourceNode。这一切都很好,并且符合规范;但是,当我尝试将输出重新连接到扬声器(使用AudioContextdestination)时,什么也没有发生。

我在这里遗漏了一些明显的东西吗?也许它与跨域音频文件有关?我只是在 Google 上找不到有关该主题的任何信息,也没有在 specs 中看到有关它的注释。

小提琴的代码是:

var a = new Audio();
a.src = "http://webaudioapi.com/samples/audio-tag/chrono.mp3";
a.controls = true;
a.loop = true;
a.autoplay = true;
document.body.appendChild(a);

var ctx = new AudioContext();


// PROBLEM HERE
var shouldBreak = true;
var src;
if (shouldBreak) {
    // this one stops playback
    // it should redirect output from audio element to the MediaElementAudioSourceNode
    // but src.connect(ctx.destination) does not fix it
    src = ctx.createMediaElementSource(a);
    src.connect(ctx.destination);
}

【问题讨论】:

    标签: javascript html5-audio web-audio-api audiocontext


    【解决方案1】:

    是的,Web Audio API requires that the audio adhere to the Same-Origin Policy。如果您尝试播放的音频不是来自同一来源,则需要相应的访问控制标头。 resource in your example 没有所需的标头。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-27
      • 2019-01-19
      • 2020-11-27
      • 2023-03-15
      • 1970-01-01
      • 2020-07-21
      • 2022-10-04
      相关资源
      最近更新 更多