gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:24:34 24 4
gpt4 key购买 nike

Here's a fiddle to show the problem .基本上,每当 createMediaElementSource AudioContext 对象的方法被调用,音频元素的输出被重新路由到返回的 MediaElementAudioSourceNode。这一切都很好,符合规范;然而,当我随后尝试将输出重新连接到扬声器时(使用 AudioContextdestination),没有任何反应。

我在这里遗漏了什么明显的东西吗?也许它与跨域音频文件有关?我在 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 .如果您尝试播放的音频不是来自同一来源,则需要适当的访问控制 header 。 resource in your example没有所需的 header 。

关于javascript - 将 MediaElementAudioSourceNode 连接到 AudioContext.destination 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29882702/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com