Sound not getting played first button click

I am using Cocos Creator 3.3.2

In my project I only have a button and when it get clicked I want to play a sound.
I have an audio source with a audio clip in the scene.

  1. But when i click the button first time the sound does not get played. If I click any ware on the scene after that, the sound does play.

  2. If I reload the scene then the button click does play the sound

  3. But if I do a hard reload in incognito mode then sound does not play on the first try

In the console I can see this message.

The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page.

Since I click the button I don’t see why the audio does not get played.

Please download the sample project with following link
https://drive.google.com/file/d/1DflxLSGrqktuVapB_IXRh3SiX5__6Psl/view?usp=sharing

Can you please advice how to get this issue fixed?

I can ask engineering to review this topic.

I think this is a browser protection thing that you need to have focus on the window before it can play sounds and maybe if you click and should play at the same time it still doesn’t have focus. So if you want it to play, then I would create some sort of await to check that the browser has registered a “focus” which would allow the browser to play sounds.

Hi, this issue is a bug that was fixed in version 3.4.0. The PR of the fix is start audioSourceBufferNode before running audio context by PPpro · Pull Request #9660 · cocos-creator/engine · GitHub, you can upgrade to version 3.4.0 and retry

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.