invalidstateerror: failed to start the audio device (ios)

Not favoritedFavorited Favorited 0 favourites
  • 4 posts
From the Asset Store
A futuristic device, can be used as radarscreen, optionscreen, infodisplay, research device, ...
  • Hi there :)

    Since the current stable version was released yesterday, I was hoping the following issue would be fixed. Unfortunately, the bug(?) still exists. I'm surprised the problem even exists and I seem to be the only one experiencing it.

    When exporting a game and running it in the Safari browser (iPhone SE, 18.3.2, also happens with 17), I get an "invalidstateerror: failed to start the audio device" error when switching back and forth between Safari and other apps. The error occurs at some point. Sometimes sooner, sometimes later.

    Is there any way I can counteract this? Is there a setting in the editor where I can, for example, prevent pausing during blur? I've only found the option for the preview. Or some kind of workaround?

    This problem has been known for a very long time. Is there any way I can access ctx manually to attempt a resume() when regaining focus from a "suspended" or "interrupted" state?

    I'd bet this issue had already been addressed and shouldn't normally occur in Construct 3, but I don't know what I could have done wrong to export a game in such a way that I get this error.

    Thanks :)

    Tagged:

  • I've never heard of that problem and it's difficult to help without knowing why it's happening. Would you be able to share a project that demonstrates the problem happening?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi Ashley,

    The problem has gone viral in the last few months (if not for two years already). If you search for "ios audiocontext suspended resume," you'll find numerous pages addressing the issue, e.g.: discourse.threejs.org/t/audiocontext-ios-17/56482/15

    This is completely game-independent. And it also affects all frameworks, if you still have an older version of Howler, for example.

    For Construct 2, the following fix works in the correct place:

    function resumeIfNeeded() {
    			setTimeout(() => {
    				if(context && (context.state === "suspended" || context.state === "interrupted")) {
    					context.resume().then(function () {
    						console.log("[audio-fix] AudioContext resumed");
    					}).catch(function (e) {
    						console.warn("[audio-fix] Resume failed:", e);
    					});
    				}
    			}, 250);
    		}
    
    		document.addEventListener("touchstart", resumeIfNeeded);
    		document.addEventListener("mousedown", resumeIfNeeded);
    		document.addEventListener("visibilitychange", function () {
    			if(document.visibilityState === "visible") {
    				resumeIfNeeded();
    			}
    		});
    

    I don't know how Construct 3 handles it. Whether it only checks for the "suspended" state, because "interrupted" also occurs frequently and must be handled accordingly.

    In Construct 2, I searched for context = new AudioContext(); and I placed the fix there. It would, of course, be great if you could access the context from "the outside", so you could place the code somewhere else.

    It is much harder to find in Construct 3, because even though minify is disabled, some things are still minified.

  • It's difficult to help from just scattered internet reports - often these combine multiple separate issues, and in fact your linked thread claims the issue is resolved in iOS 17.1 in the last post, so if it still happens in newer iOS versions, either that thread is talking about some other issue, or the information is incorrect.

    I've been doing this a long time and it's generally not possible to help without clearer information, so if you'd like us to properly investigate this, please file an issue following all the guidelines, which ensures we have everything we need to be able to help.

Jump to:
Active Users
There are 2 visitors browsing this topic (0 users and 2 guests)