Hello ,
recently we discovered that we are having issues with audio playback using PlayCanvas on iOS.
We were able to work around our issue but I want to provide a little context and hope that someone finds this useful or can even help with resolving the issue completely.
Our PlayCanvas game uses a WKWebView as host environment on iOS.
What’s important to know is, that the game is only part of a larger iOS app, so it’s not always in the foreground when using the app.
Rather than just loading this WebView each time the user navigates to the game, waiting for the site to load and then showing the scene, we load the WKWebView in the background (off-screen) and then just display the fully loaded site when the user enters the game.
The site stays in memory even when the user leaves the game and is “resumed” as soon as the user comes back in.
Though having a lot of advantages for loading times this approach provided some challenges.
One of them being that audio playback e.g. for FXs or background music stops working after the user first exits from the WebView (essentially hiding it) or bringing the app in the background.
Furthermore we get the following debug error log from iOS (not JS) despite having had working audio before, having setup all necessary entitlements, permissions and capabilities and configuring the WKWebView for media playback without restrictions:
[assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=3 "Required client entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"MediaPlayback" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Required client entitlement is missing}>
[ProcessSuspension] 0x1104d8a50 - ProcessAssertion: Failed to acquire RBS MediaPlayback assertion 'WebKit Media Playback' for process with PID 1765, error: Error Domain=RBSAssertionErrorDomain Code=3 "Required client entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"MediaPlayback" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Required client entitlement is missing}
As a side-note WebKit has a bug reported as fixed in iOS 13+ addressing that issue.
That seems to not apply to us.
We did work around our issue by calling
pc.app.systems.sound.manager.context.resume()
based on what was stated here https://forum.playcanvas.com/t/no-audio-playing/2586/20, but this seems to be only a mediocre fix to the underlying problem.
This leads to sound being played again, but keeps the assertion failures still flooding the iOS console.
Just for context I’m gonna leave our environment here:
- PlayCanvas 1.41.2 84a4993
- iOS 14.4.2
My questions to the community are:
- Has this happened to you as well? If so, how did you fix it?
- Does anyone know what WebKit is telling with that assertion and how to mitigate the effect?
- Can there be an extension to
pc.SoundManager
to allow restarting/re-attaching to the AudioContext when bringing WebViews from the background?
Thanks for your help