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() {
soundComponent.play("Jump");
}, 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