📣 Help shape Firefox by joining our Test Days event on July 21–Aug 1 to test the Firefox Semantic History Search in Firefox Beta 142

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

Under some circumstances Firefox won't play sound played from javascript.

  • No replies
  • 1 has this problem
  • 1 view

I was following the tutorial at http://www.w3schools.com/games/game_sound.asp. If you look at the page you should see a small game. When the red square hits a green line it should play a sound, but Firefox does not.

Firefox does not appear to play a sound triggered at page load, through setInterval or setTimeout or in the console, unless the user has triggered it directly first.

For example using the following:


<script> var sound = new Audio("soundfile.ogg"); sound.play(); function startPlayRepeat() { setInterval(playSound, 500); } function startPlayDelay() { setTimeout(playSound, 500); } function playSound() { sound.play(); } </script> <button onclick="playSound()">Play sound</button> <button onclick="startPlayDelay()">Play sound delay</button> <button onclick="startPlayRepeat()">Play sound repeat</button>


What should happen here: 1. The sound plays on loading the page. 2. The sound plays with a half second delay if you press "Play sound delay". 3. The sound plays repeatedly with a half second interval if you press "Play sound repeat". 4. The sound plays if you enter playSound() or sound.play() in the console.

But the sound never plays unless I've pressed "Play sound" first (impossible for #1).

If there are two audio objects, then playing one will not make the other work. They have to be played individually.

I was following the tutorial at http://www.w3schools.com/games/game_sound.asp. If you look at the page you should see a small game. When the red square hits a green line it should play a sound, but Firefox does not. Firefox does not appear to play a sound triggered at page load, through setInterval or setTimeout or in the console, unless the user has triggered it directly first. For example using the following: ------ <html> <body> <script> var sound = new Audio("soundfile.ogg"); sound.play(); function startPlayRepeat() { setInterval(playSound, 500); } function startPlayDelay() { setTimeout(playSound, 500); } function playSound() { sound.play(); } </script> <button onclick="playSound()">Play sound</button> <button onclick="startPlayDelay()">Play sound delay</button> <button onclick="startPlayRepeat()">Play sound repeat</button> </body> </html> ------ What should happen here: 1. The sound plays on loading the page. 2. The sound plays with a half second delay if you press "Play sound delay". 3. The sound plays repeatedly with a half second interval if you press "Play sound repeat". 4. The sound plays if you enter playSound() or sound.play() in the console. But the sound never plays unless I've pressed "Play sound" first (impossible for #1). If there are two audio objects, then playing one will not make the other work. They have to be played individually.