Hide audio button while keeping the audio

Hi!

I’m currently facing an issue with the audio. At the moment, I need to click on the small mute/unmute button in the top left corner of the scene to mute/unmute the audio of my game.

Screenshot 2022-12-21 091354

The issue is that I would my audio to play when it is ready without having to enable/disable the button. At the moment, I’m able to remove the audio button via this line of code

Engine.audioEngine.useCustomUnlockedButton = true;

but then, no sound is playing even if I do

mySound.play();

What line of code should I add to make that possible?

Thanks

There’s no line that makes that possible, as every browser requires an user interaction to start audio :sweat_smile: Which is a good thing if you think about it, imagine if ads could just start blaring audio at full volume :slight_smile:

1 Like

Yes I understand that …:sweat_smile:

However, can we hide the button and enable the audio when the player click on the screen?

1 Like

Ooooh, my bad, I understood you were asking something different :sweat_smile: I dug a bit more in the audio engine, and I could get it to play on click by calling unlock on pointer down: Sounds not ready to play | Babylon.js Playground (babylonjs.com) (it looks like that doesn’t work if the unlock isn’t inside a user interaction, which makes sense)

1 Like

Thanks for the quick reply! However, the audio button is still there and I still have to click on it to enable the audio…

1 Like

Huh, weird, which browser are you using? :open_mouth: I tested on Edge, Chrome and Firefox but the behavior can be browser dependent :thinking:

1 Like

I tested on Chrome and Edge.

Hey @Rangerz132 just checking in if you’re still having this issue?

Hi! I find out that this issue was only occurring when I was reloading the page which is strange but it’s ok! Thanks

That means the issue is not solved, and anyone visiting the site fresh will have the issue.

The docs don’t even mention how to deal with this highly-annoying unmute button:

Audio | Babylon.js Documentation (babylonjs.com)

The example from those docs, aptly titled “Sounds not ready to play”, does not even work without unmuting! :joy:

Sounds not ready to play | Babylon.js Playground (babylonjs.com)

If you can show me an example that never shows the unmute button, and tapping will always run the gunshot sound, on iOS Safari, I will be amazed.

Hi,
May be ask @RaananW ? I had the understanding that we would get a refounded (actually new founded) audio component, isn’t it? Since I’m not into making audio at this time I didn’t follow-up.

Alright, check out this example, works beautifully…

autoplay sound on click (iOS broken) | Babylon.js Playground (babylonjs.com)

… until you try it on iPhone. It’s always iPhone! (Works fine in macOS.)

People suggest that we simply call audioEngine.unlock() in a user interaction, f.e.

but iPhone said “not today!” :joy:

OMG, look at that! iPhone starts to work on click, but not on pointerdown!

autoplay sound on click (iOS fixed, using click) | Babylon.js Playground (babylonjs.com)

I think Babylon should simply provide an option like audioEngine.noMute = true and simply never show that pesky unmute button by default. It should simply work out of the box.

No one wants that unmute button by default. It’s a bother, and difficult to get right.

What is worse is that, if you call unlock() in pointerdown on iPhone, it never works again. The unmute button doesn’t even work after that!! Click it and it never goes away!!

Need to obliterate that darn unmute button.

solution here: