繁体   English   中英

Javascript Audiocontext 振荡器在 Windows Edge 或 Android 浏览器上不工作

[英]Javascript Audiocontext Oscillator Not Working on Windows Edge or Android Browsers

代码已完成。 没有发出声音。 尝试在 Windows Edge 版本 109.0.1518.70(官方构建)(64 位)上重新安装 Andriod OS 以及 Windows 安装和升级。 我尝试了 2021 年在我以前的手机上运行的旧 Audiocontext 振荡器应用程序代码。没有。 所有其他离线和在线声音应用程序都可以工作。

alert("your code is ok to run")
var audioContext = new window.AudioContext()
alert("recognise audio object")
var oscillator = audioContext.createOscillator();
alert("recognise oscillator object")
oscillator.connect(audioContext.destination);
//I am going to say 440
alert(oscillator.frequency.value)
oscillator.start(0)
alert("the code compiled. yeah!, increase the volume. can you hear it? I cant.")

如果您不能加热任何东西,很可能是浏览器的自动播放策略阻止了它。 您需要运行代码以响应用户操作。 例如,如果您在按钮的点击处理程序中执行此操作,它应该会按预期工作。

document.getElementById('the-id-of-a-button').onclick = () => {
    // the code from above
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM