Quantcast
Channel: 2D Latest Topics
Viewing all articles
Browse latest Browse all 623

So, what's the deal with sound?

$
0
0

Hi! I've been trying to get my JavaScript game to play sound using the HTML5 audio stuff.

I am getting a security error when I run the ".play" method. From my research, this is a new security measure implemented into Google Chrome regarding auto-play on websites. Does anyone know how to get around it?

Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first.

I've tried the "SoundJS" and "HowlerJS" libraries. Both of these libraries are rendered inoperable by the new error. The only workaround I've found is making audio play (running ".play()" on a keypress) This makes sense, as Chrome doesn't want its users being caught off guard with random audio. However, I need my game to play audio on its own accord. (sound effects,  some ambiant music randomly begins, etc)

Right now, I'm trying the instructions found here. When I put that exact code into my code, it throws the error - but when I play the demo on their site of presumably the same code, it runs fine and I can hear the sound in their example. How come I can here everything fine in their example, but their exact code throws an error in mine? (And doesn't play any sound!)

Any help with this issue would be awesome. I'm so tired of trying different libraries, different methods, trying to work with the "Promise" system, and more. So believe me, any help would be GREATLY appreciated! Yikes!  😂


Viewing all articles
Browse latest Browse all 623

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>