Αναζήτηση στην υποστήριξη

Προσοχή στις απάτες! Δεν θα σας ζητήσουμε ποτέ να καλέσετε ή να στείλετε μήνυμα σε κάποιον αριθμό τηλεφώνου ή να μοιραστείτε προσωπικά δεδομένα. Αναφέρετε τυχόν ύποπτη δραστηριότητα μέσω της επιλογής «Αναφορά κατάχρησης».

Learn More

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

  • Καμία απάντηση
  • 1 έχει αυτό το πρόβλημα
  • 4 προβολές
more options

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.