Javascript Audiocontext Oscillator Not Working on Windows Edge or Android Browsers

74 Views Asked by At

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

There are 1 best solutions below

0
On

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
};