Sound disappears after a prompt() call

How do I keep the audio after a prompt() call?
(I’m using prompt because it’s easier for user to enter the url on any device.)

Every time a prompt() is called, the audio will toggle from on to off or vice versa.

Hi @FBa,

Could you provide a playground repro-ing the issue?

In this playground, the prompt call is not interfering with the audio.

I just added a prompt() call to one of the playgrounds from the Sound docs and it seems to be working just fine.

I can’t paste the code right now… But you can go to

First: Swipe through the keys after you unmute…you should hear sound from the keyboard as you move your fingers through.

Click Load My Music --> Click Cancel or OK without inputting any text --> You will notice that the sound is muted at this point as you swipe through the keys (for some reason) --> Click Start --> I use another alert window just so that sound can be toggle back to be unmuted.

Bizarre, not? For some reason the prompt window mutes the sound. So I need a double “prompt” to bring the sound back.

Ah, I see what i you are saying. Unfortunately, it will be hard to figure out the root cause without seeing some code.

Maybe you are interfering with the render loop when the prompt is called? That is my best guess right now.

1 Like

Oh wait, I have a hypothesis:

When you are calling prompt(), you are blocking the JS execution thread, stopping the music.

Can you repro this using a custom modal (not using window.prompt, or alert, or confirm, etc…)?

There is no render loop actually.

You can test this easily by having two buttons, each button will play a track upon click. Also each button will prompt() as well. You will see what I mean.

A repro in the PG will help accelerate getting an answer :slight_smile:

Every 2nd, 4th, 6th time after I finish my prompt() the sound comes on.
Every 1st, 3rd, 5th, 7th time after I finish my prompt() the sound stops.
And it doesn’t matter which button I’m clicking.

var createScene = function () {

var scene = new BABYLON.Scene(engine);

var camera = new BABYLON.FreeCamera(“FreeCamera”, new BABYLON.Vector3(0, 0, 0), scene);

var music1 = new BABYLON.Sound(“Violons11”, “sounds/violons11.wav”, scene,

function() {});

var music2 = new BABYLON.Sound(“Violons18”, “sounds/violons18.wav”, scene,

function() {});

var play1 = function soundReady() {;prompt("SOUND1", "");


var play2 = function soundReady2() {;prompt("SOUND2", "Harry Potter");


advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");

 button10 = BABYLON.GUI.Button.CreateSimpleButton("but", "Toggle Colors");

    button10.width = 0.2;

    button10.height = 0.075;

    button10.color = "white";

    button10.background = "green";

    button10.thickness = 0;

    button10.alpha = 0.7;

    button10.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT;

    button10.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_BOTTOM;



    button11 = BABYLON.GUI.Button.CreateSimpleButton("but", "Load My Own Music");

    button11.width = 0.2;

    button11.height = 0.075;

    button11.color = "white";

    button11.background = "gray";

    button11.thickness = 0;

    button11.alpha = 0.7; = "-100px";

    button11.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;

    button11.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_BOTTOM;



return scene;


Why not dropping that into the playground? Is there something wrong ?

How do I do that? (I have only used BabylonJS for three weeks). I use mainly JSFiddle to test my code at this point.

drop your code here and share the result:

doc: Introduction to the Playground - Babylon.js Documentation

Seems like it is working as expected, no?

The sound is playing, prompt is opened. A new sound is playing every time I press any of the buttons.

Want to explain what exactly not working in this example?

Every 2nd, 4th, 6th time after I finish my prompt() the sound comes on.
Every 1st, 3rd, 5th, 7th time after I finish my prompt() the sound stops.

what browser are you using? I can’t reproduce that.

Ouch you are right. Chrome is fine and Safari isn’t.
Can you try Safari? So what to do for those using the future “game” that I will release? Is there a way to unmute in Safari?

Safari is the new IE! :slight_smile:

I don’t have a mac, can’t quite test that, have you tried other browser to see if safari is the exception or chrome is?

1 Like

Just tried Firefox. Firefox works.

I am really sorry that i can’t test that, but it might be a browser issue that we can’t overcome. is there maybe a combination of actions that might get it to work? wrap the play in a setTimeout?

That’s why I’m curious if anyone else wrote a game that involves prompt() has a workaround. BabylonJS is a cross-browser friendly platform…we don’t want to lose all our Safari users, do we?