Dom83 Posted April 5, 2022 Share Posted April 5, 2022 (edited) Hello Do you guys get WebAudio working on iOS ? I can't... ( my game : https://www.html5gamedevs.com/topic/47762-8-bit-pocket-wrestlers/ ) Safari seems to load and decode the sounds, but stays silent. I did run some tests and found out that my problem is just the infamous "no sound unless caused by a click on something" issue. ( https://dom83.xyz/games/8bit_pocket_wrestlers/_debug_webaudio.php , no sound unless caused by a click on "start". ) Worse, Opera, which is actually just a WebView, acts like the audio files don't exist at all. So in order to keep the game from being stuck on the loading screen I had to disable sound if "AppleWebKit" is found in the user agent. ( Add "?force_webaudio_on" to the url of my game to force webaudio on and see the problem. ) My _debug_webaudio.php test works though, so there may be a problem in my game. But there seems to be no way to debug javascript in Opera so I am stuck... Blocking WebAudio is a stupid decision for the user can mute the tab if needed, but there is no point in discoursing on this. We need a solution. What I am trying right now is to wait for the first click/touch (on the language selection screen at the start of the game) to load and play a first sound, hoping that this may unlock WebAudio afterward. For now, it does not work at all, even this first sound won't play for some reason. Do you guys get WebAudio working on iOS ? How ? Or do you have an alternative ? The older audio API is not an option, it can't loop properly, you can't control playing speed and so on. Edited May 23, 2022 by Dom83 solved Quote Link to comment Share on other sites More sharing options...
Dom83 Posted April 18, 2022 Author Share Posted April 18, 2022 (edited) I eventually got to get it working. You must wait for the user to click somewhere to play a first sound, but you also have to call audioctx.resume(); , or else audioctx.state will stay "suspended". After that, it works. In order for it to work in Opera (WebView) I also had to remove a setTimeout() in my function for some reason. Edited May 23, 2022 by Dom83 Quote Link to comment Share on other sites More sharing options...
Saint_Pepsi Posted May 22, 2022 Share Posted May 22, 2022 @Dom83 Have you tried using Howler.js? I don't even want to try dabbling with web interface audio anymore after countless hours of headaches Quote Link to comment Share on other sites More sharing options...
Dom83 Posted May 22, 2022 Author Share Posted May 22, 2022 (edited) No, I have not tried. I never use libraries. But thanks for the suggestion. As far as I can test, the method I described seems to work. (but I have only one iOS device to test on) If some people still struggle : - check if the useragent contains the string "safari" - create the audiocontext as usual - but wait for the user to click somewhere before you play a first sound, linked to a user click, which will "unlock" webaudio and let you use it afterward. In my case I do it on the language selection screen since I have one, you can display a "click here to start this webapp" screen instead or something like that. - and just before decoding and playing that first sound, don't forget to call audioctx.resume(); - To avoid crashes if it doesn't work, check audioctx.state , if its value is still "suspended" then disable sound, or else trying to decode and play sounds might crash your game like it crashed mine. Edited May 23, 2022 by Dom83 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.