Audio Not Playing in a WKWebView

Hello!

i built an xCode project with a single WKWebview component to make my game into a mobile app. Everything is working really great but no audio is being played from my PlayCanvas in the WkWebview. Any tips for this? Im not really sure how the audio works under the hood so hard for me to trouble shoot

Thanks,
Mitch

Hi @MitchMeyer1,

It seems you can configure the wkwebview to require user interaction for audio ON/OFF. This image is from Xcode storyboard settings but there should also be possible to configure that properties in code also.
Screenshot 2022-04-04 at 21.18.19

You may also want to add some add some user interaction in your javascript eg https://playcanvas.com/editor/scene/1024791

1 Like

Hmm yeah I actually tested with a different pc game (SWOOOP - PLAYCANVAS) instead off mine and it plays the sound, so i think my xcode project is not at fault here. I dont play sound until after the user logs in and goes to other scenes so theres for sure user interaction first. Im not really sure what the issue could be

Could be related to this issue we had with with Cordova

https://developer.playcanvas.com/en/user-manual/publishing/mobile/cordova/#adding-your-playcanvas-app

Not sure why Swoop works thoughm

Hey so i found the issue,

My server was feeding me game files with names like:
https://bluestreak-production.s3.amazonaws.com/tmp/000000f6-bff8-478b-9939-5baef61f4669.mp320220120-15-sjzogl

As you can see - the file extension is “.mp320220120-15-sjzogl”, this still played on chrome and firefox but not on Safari or WKWebview. I corrected my server to serve only .mp3 without the additional characters and it worked!

Guess it was a safari issue with my file type and not really anything to do with playcanvas

1 Like

As a follow up - this didn’t solve my mobile safari problem, i thought it did but it did because my login button triggering music worked - but later when sound affects from game events triggered sound it was still broken.

After some research it seems that with <audio> tags or javascript new Audio() functions, they need to be played/triggered from within the context of a user interaction event (like click or touchdown)

Long story short - i ended up using Playcanvas’ Sound component and it worked great, if you want sound in your game don’t use html <audio> tags or javascript new Audio(), just use Playcanvas’ sound component system.

2 Likes