将 MediaElementAudioSourceNode 连接到 AudioContext.destination 不起作用

Connecting MediaElementAudioSourceNode to AudioContext.destination doesn't work

Here's a fiddle to show the problem. Basically, whenever the createMediaElementSource method of an AudioContext object is called, the output of the audio element is re-routed into the returned MediaElementAudioSourceNode. This is all fine and according to spec; however, when I then try to reconnect the output to the speakers (using the destinationAudioContext), 没有任何反应。

我是不是遗漏了什么明显的东西?也许它与跨域音频文件有关?我只是在 Google 上找不到关于该主题的任何信息,并且在 specs.

上也没有看到它的注释

来自 fiddle 的代码是:

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);
}

是的,Web Audio API requires that the audio adhere to the Same-Origin Policy. If the audio you're attempting to play is not from the same origin then the appropriate Access-Control headers are required. The resource in your example 没有所需的 headers。