greeting everyone, i am trying to make notification system but when i play notification sound i get the following error ( the user must intercative with the page )
Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first.
my script
<script>
let contact = new Audio("{{ asset('assets/sounds/contact.wav') }}");
Echo.private(`contact`)
.listen('ContactEvent', (e) => {
contact.play()
alert('hello')
});
</script>
Autoplaying audio/video can be a shitty user experience...
Automatically starting the playback of audio (or videos with audio tracks) immediately upon page load can be an unwelcome surprise to users. While autoplay of media serves a useful purpose, it should be used carefully and only when needed. In order to give users control over this, browsers often provide various forms of autoplay blocking. In this guide, we'll cover autoplay functionality in the various media and Web Audio APIs, including a brief overview of how to use autoplay and how to work with browsers to handle autoplay blocking gracefully.
@tykus i am not looking to make audio start immediatly, some thing like facebook messenger when u open facebook and someone text you , you will get notification sound even if u dont make any clicks on the pages
@CrastyCrap There is no way to do this unfortunately, it's the browser that is blocking the sound from being played. This is a feature that was added some time ago. I've had the same issue, and the only way around it is to make the user do some things with the page before you tries to play the sound.