[SOLVED] iOS WebView not playing sound through app.fire

For some reason, when running my game in an iOS WebView, it only plays the Music and silences all sound output.

I’ve read that this is because iOS requires input to play sound, but people using this fix say it solves the problem for them:

        let webConfiguration = WKWebViewConfiguration()
        webConfiguration.allowsInlineMediaPlayback = true
        if #available(iOS 10.0, *) {
            webConfiguration.mediaTypesRequiringUserActionForPlayback = []
        } else {
            webConfiguration.mediaPlaybackRequiresUserAction = false
        webView = WKWebView(frame: .zero, configuration: webConfiguration)

This doesn’t solve the problem for me. I still hear no sound output.

This is how I request the sounds to play:

From an Update function, I call my own function that then performs: this.app.fire(“trigger:jumped”);

In an Initialize function, I have this code:

    app.on("trigger:jumped", function() { 
    }, this);

EDIT: It turns out that this problem is not because of how I’m triggering the sound to play. No matter what I’ve tried so far, from playing the audio directly from touch events or even in a random Update function, it’s simply not playing.
However, in testing, I loaded the debugger version on my iPhone. It displayed an error message that is either specific to the debugger, or is simply hidden in the final build. If it is the latter, then this may be the true root of my problem. This was the error: [Error loading audio url: /api/assets/files/jump.mp3?id=(NUMBERS)&branchId=(UNIQUE ID)&t=(NUMBERS+LETTERS)]

I’ve downloaded and reuploaded the file in question and the only thing that changed was the id. This error is displayed on the loading screen. This is likely the root of my error, and it is also likely iOS specific since it works perfectly fine on web and on android. It happened in chrome, safari, and my webview. Again, the music loads just fine and it is stored the exact same way in my assets as this jump sound asset.

Any advice on how to fix this? Thanks!

Project Link: https://playcanvas.com/project/599997/overview/hydra-run

Hi @haidarcorp,

It’s been a while since the last time I’ve used a WebView in iOS, but your issue reminds me of the following:

Posting in case it provides a resolution for you.

Unfortunately this is the same one I was referencing and it doesn’t. I don’t actually think it has to do with my specific webview, it’s likely an iOS system wide problem.

I’m fairly confident the issue is that the audio file url can’t be loaded, but the reason behind that is beyond me and seems like it should work just fine.

In a pleasant turn of events, I solved the problem! By downloading the “problemed” audio clip, trimming it and in turn creating a new audio clip, and then re-uploading the new audio clip, it now works.

1 Like

Thanks for sharing!

1 Like