简体   繁体   中英

Javascript Audiocontext Oscillator Not Working on Windows Edge or Android Browsers

The code is complete. No sound produced. Tried on Windows Edge Version 109.0.1518.70 (Official build) (64-bit) Fresh reinstall of Andriod OS and also Windows Install and Upgraded. I have tried old Audiocontext Oscillator app code that worked on my previous mobile phones in 2021. Nothing. All other offline and online sound apps work.

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.")

If you can't heat anything it's most likely blocked by the browser's autoplay policy. You need to run your code in response to a user action. If you would for example do it within a button's click handler it should work as expected.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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