我正在使用网络音频,并且下面的代码在Chrome中可以正常运行,但在Safari中不能正常工作。
const audioContextList = [];
(function () {
self.AudioContext = new Proxy(self.AudioContext, {
construct(target, args) {
const result = new target(...args);
audioContextList.push(result);
return result;
}
});
})();
在Safari中,出现以下错误:
TypeError:代理的“目标”应为对象
我该如何解决?
带有供应商前缀:webkit的Safari 13.1supportsAudioContext
。>>
因此您应该使用self.webkitAudioContext
访问它。或者您可以制作一种跨浏览器的解决方案
let AudioContext = self.AudioContext || self.webkitAudioContext;
self.AudioContext = new Proxy(AudioContext, {
construct(target, args) {
const result = new target(...args);
audioContextList.push(result);
return result;
}
});