Auto play getting muted in both firefox and chrome. How can we code, so it won't get blocked by browsers.
My Code :
<audio id="audio1" src="https://notificationsounds.com/storage/sounds/file-sounds-1217-relax.mp3" autoplay="">
<script>
a = document.getElementById('audio1');
a.onended = function(){setTimeout("a.play()", 1000)}
</script>
This is a browser feature and it is enforced by a policy. Your page must have some continuous activity in order to do so.
As suggested by the comments, you can indeed wait for onClick events in order to trigger your playback.
Technically speaking, the referenced document says that for a developer standpoint of view you can alter them to perform specific tests:
You can disable the autoplay policy entirely by using a command line flag: chrome.exe --autoplay-policy=no-user-gesture-required. This allows you to test your website as if user were strongly engaged with your site and playback autoplay would be always allowed.
You can also decide to make sure autoplay is never allowed by disabling MEI and whether sites with the highest overall MEI get autoplay by default for new users. Do this with flags: chrome.exe --disable-features=PreloadMediaEngagementData, MediaEngagementBypassAutoplayPolicies.