![](/img/trans.png)
[英]Uncaught TypeError: Failed to execute 'insertBefore' on 'Node': parameter 1 is not of type 'Node'
[英]Uncaught TypeError: Failed to execute 'createMediaElementSource' on 'AudioContext': parameter 1 is not of type 'HTMLMediaElement'
我目前正在尝试在 JavaScript 中创建一个音频可视化器,并且这个错误不断被抛出:
未捕获的 TypeError:无法在“AudioContext”上执行“createMediaElementSource”:参数 1 不是“HTMLMediaElement”类型。
我不太确定如何解决该错误,我一直在互联网上寻找答案,但似乎没有任何帮助。
当您点击播放时,音乐确实会播放,但我需要我的可视化工具来接受来自音频元素的数据,这样我才能拥有一个可以工作的可视化工具。
这是您的代码的一部分:
let audioCtx = new (window.AudioContext || window.webkitAudioContext)();
let audio = document.querySelector('song1');
let analyser = audioCtx.createAnalyser();
let source = audioCtx.createMediaElementSource(audio);
您尝试获取元素song1
,但它在 HTML 中不存在。 这可能就是您收到此错误的原因。 此外,如果您尝试通过 id 检索元素,您应该这样做
let audio = document.querySelector('#song1');
然后在你的 html
<audio id="song1" controls="">
然后我检查了你会得到其他错误,但这回答了你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.