Jump to content

(solved) WebAudio on iOS, still no solution in 2022 ?


Recommended Posts


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 by Dom83
Link to comment
Share on other sites

  • 2 weeks later...

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 by Dom83
Link to comment
Share on other sites

  • 1 month later...

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 by Dom83
Link to comment
Share on other sites

  • Dom83 changed the title to (solved) WebAudio on iOS, still no solution in 2022 ?

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...