The AudioContext was not allowed to start

In my app i have button for sound start but if i click on it the mute button of babylonjs comes.
Is there any possiblity to make audio directly start if i click on the button?

      case "engine":
        resumeAudio();
playSound();
        break;

let audioContext = new (window.AudioContext || window.webkitAudioContext)();
function resumeAudio() {
  if (audioContext.state === 'suspended') {
      audioContext.resume().then(() => {
          console.log('AudioContext resumed');
      });
  }
}

You have to disable the default unlock and call audioEngine.unlock() from your button/user interaction

https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#handling-autoplay--unlocking-audio-on-first-user-interaction

1 Like