我正在编写用于音频的可视化程序,并且在mac os x和使用远程调试器进行的ios调试上存在关于Safari的问题。在用于更新AudioContext分析器的动画功能上,ByteFrequency数组中的值未在野生动物园中更新。下面是代码示例:
var context;
if (typeof AudioContext !== "undefined") {
context = new AudioContext();
} else if (typeof webkitAudioContext !== "undefined") {
context = new webkitAudioContext();
}
var analyser = context.createAnalyser();
analyser.fftSize = 64;
frequencyData = new Uint8Array(analyser.frequencyBinCount);
// Get the frequency data and update the visualisation
function update() {
requestAnimationFrame(update);
analyser.getByteFrequencyData(frequencyData);
};
$(document).ready(function(){
$("#player").bind('canplay', function() {
var source = context.createMediaElementSource(this);
source.connect(analyser);
analyser.connect(context.destination);
});
};
这里是工作示例http://basketballjock.org/的链接
在野生动物园中,您需要在用户交互后创建音频上下文。例如,在按钮上的onclick回调。