I am trying to play audio on the page load. I have a website that sends a notification to users and plays a notification sound. Sometimes the notification is sent before user interaction with the browser, in this case, the sound is not getting played.
I am using the following code:
const audioCtx = new AudioContext();
const audio = new Audio(site_url+"/audio/pristine.mp3");
const source = audioCtx.createMediaElementSource(audio);
source.connect(audioCtx.destination);
audio.play();
Please guide me what can be done about this.