[英]HTML 5 Audio - AnalyserNode.getByteFrequencyData() Returns Undefined
This appears to be a common question - Javascript Web Audio API AnalyserNode Not Working - But I can't be sure if I've found an edge case with my implementation. 这似乎是一个常见的问题 - Javascript Web Audio API AnalyserNode不起作用 - 但我不能确定我是否找到了我的实现的边缘情况。
I create an audio source using createMediaElementSource(), but instead of using an audio tag from the page markup, the element is created dynamically using Buzz.js. 我使用createMediaElementSource()创建音频源,但不是使用页面标记中的音频标记,而是使用Buzz.js动态创建元素。
Here's my test setup: 这是我的测试设置:
window.addEventListener('load', function(e) {
audioContext = new webkitAudioContext();
audioAnalyser = audioContext.createAnalyser();
sound = new buzz.sound("sound.mp3");
sound.load().bind("canplaythrough", function(e) {
source = audioContext.createMediaElementSource(this.sound);
source.connect(audioAnalyser);
audioAnalyser.connect(audioContext.destination);
this.play().loop();
});
}, false);
window.setInterval(function(){
array = new Uint8Array(audioAnalyser.frequencyBinCount);
console.log(audioAnalyser.getByteFrequencyData(array));
})
With the code above, the sound plays. 使用上面的代码,声音播放。 I can also attach others nodes (biquad filters, gain etc) which work, but the audioAnalyser.getByteFrequencyData returns undefined values on every frame...
我还可以附加有效的其他节点(双二阶滤波器,增益等),但audioAnalyser.getByteFrequencyData会在每一帧上返回未定义的值...
Might it have anything to do with using Buzz.js? 可能与使用Buzz.js有关吗?
It was a failure of comprehension... 这是一种理解的失败......
Basically, I was expecting the console to log some kind of output from the following: 基本上,我期待控制台记录以下某种输出:
window.setInterval(
array = new Uint8Array(audioAnalyser.frequencyBinCount);
console.log(audioAnalyser.getByteFrequencyData(array));
)
What I should have done was this: 我应该做的是这样的:
window.setInterval(function(){
array = new Uint8Array(audioAnalyser.frequencyBinCount);
audioAnalyser.getByteFrequencyData(array);
console.log(array);
})
A bit silly, but I hope that helps anyone coming here who might have expected getByteFrequencyData to return a value of somekind. 有点傻,但我希望这有助于任何来到这里的人可能期望getByteFrequencyData返回somekind的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.