1

Is there any way to make a sound spam from the beginning? So far I have this:

<audio controls src="https://www.dropbox.com/s/a6wqamnhhmprvwu/OOF.wav?dl=1"  id="audio"></audio>
<script>
var one;setInterval(two,1);
function two{
var audio = document.getElementById("audio");
audio.pause();
audio.currentTime = 0;
audio.play();

}
</script>
Komali
  • 77
  • 10
  • 1
    i looked up the word `spam` to try to figure out what the hell you're talking about and found the word has two definitions.. 1) unwanted messages, and 2) a canned meat product. don't see how either of those definitions could possibly be relevant. think you could elaborate? – I wrestled a bear once. Apr 11 '18 at 18:24
  • whatever it is you're doing, the fact that you're doing ti every millisecond is probably part of the problem. – I wrestled a bear once. Apr 11 '18 at 18:26
  • You can use `audio.addEventListener('ended'` in place of the interval. – Zac Apr 11 '18 at 18:29
  • @Occam'sRazor Spamming often means to do something over and over again, although it's a negative word, and is related to the first definition you found. It usually means to do something more than necessary. – Carcigenicate Apr 11 '18 at 18:30
  • If you're trying to loop the audio then why not just set the loop attribute to true. And in general. why not try googling or reading some documentation before asking a question. – I wrestled a bear once. Apr 11 '18 at 18:32

1 Answers1

3

Increase the interval to 1000 ms

<audio controls src="https://www.dropbox.com/s/a6wqamnhhmprvwu/OOF.wav?dl=1"  id="audio"></audio>
<script>
setInterval(two, 1000);    
function two() {
  var audio = document.getElementById("audio");
  audio.pause();
  audio.currentTime = 0;
  audio.play();
}
</script>
Zac
  • 2,201
  • 24
  • 48