I have a chat, and users re supposed to send sounds as messages and these should play automatically upon receiving them. However, this restriction: "The play method is not allowed by the user agent or the platform in the current context, possibly because the user denied permission" is giving me a hard time. Is there any way to circumvent this? I tried with observers like this:
if(mutation.type === 'childList' && mutation.addedNodes[3]?.className == 'sounds') {
var audio = new Audio('sound.mp3');
audio.play();
}
or by inserting directly into the html of the receiver:
<audio autoplay><source="sound.mp3" type="audio/mpeg"></audio>
but the audio wont autoplay if its dynamically added to the DOM like this. I mean, I get it, its annoying to hear sounds unexpectedly if you dont ask for them but thats why my users have the option to disable them on their settings so those who have it enabled want to hear those sounds.
Any ideas?
Via Active questions tagged javascript - Stack Overflow https://ift.tt/Aj5OMb1
Comments
Post a Comment