![](/img/trans.png)
[英]AudioContext Analyser working on firefox/chrome but not Safari
[英]AudioContext not working on Safari but working on Google Chrome
我知道我需要在 Safari 中的用户交互后创建音频上下文。 但是,以下代码仍然无效。
HTML
<button onclick="play">Play</button>
Javascript
function play() {
var AudioContext = window.AudioContext || window.webkitAudioContext
var ctx = new AudioContext()
fetch('MP3_URL')
.then((response) => response.arrayBuffer())
.then((arrayBuffer) => ctx.decodeAudioData(arrayBuffer))
.then((audioBuffer) => {
var source = ctx.createBufferSource()
source.buffer = audioBuffer
source.connect(ctx.destination)
source.start(ctx.currentTime)
})
}
在 Google Chrome 错误 safari 上工作的相同代码。
我在这里做错了什么吗? 非常感谢!!
我对我来说真的没有意义,但在这种情况下 Safari 需要再次推动才能启动AudioContext
。 在创建AudioContext
后立即调用resume()
应该可以工作。
// ...
var ctx = new AudioContext();
ctx.resume();
fetch('MP3_URL')
// ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.