xpenatan / gdx-teavm

Run Libgdx in a webbrowser with teavm
Apache License 2.0
107 stars 16 forks source link

The AudioContext was not allowed to start #117

Closed Quillraven closed 4 months ago

Quillraven commented 5 months ago

Hi,

I have again an issue with playing audio in the Browser Link to the game.

According to the browser console: image image

It seems like calling Music.play() fails if it is called at the application startup? If I control the player (WASD, SPACE) then e.g. I can here the sound for the jump effect and also the jingle when I get in contact with the finish flag. But the normal background music of the map is not played.

Can I somehow force a gesture to also play music immediately without an interaction of the user first? Or is there another solution to this issue?

edit: by the way, I use Edge as a browser.

xpenatan commented 4 months ago

I dont think there is a way to force a gesture. What they recommend is to add a play button at start of the game to be the first interaction .

https://gamedev.stackexchange.com/questions/163365/html5-games-play-failed-because-the-user-didnt-interact-with-the-document-fi https://stackoverflow.com/questions/64929753/play-failed-because-the-user-didnt-interact-with-the-document-first-issue https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide

Quillraven commented 4 months ago

Thanks for responding. I actually did a similar solution now. After preloading some resources I show a text to the user "click to continue" and only after that touch event, I go to the real game and from there music playing is working.

Thank you xpenatan :)