Audio loop Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Audio

Description

The loop property sets or gets whether an audio should play again and again.

This property reflects the <audio> loop attribute.

Set the loop property with the following Values

Value Description
true|false Sets whether the audio should start playing over again, every time it is finished
  • true - play again and again
  • false - Default. Audio should NOT start playing again when it is finished

Return Value

A Boolean, returns true if the audio starts playing over again, every time it is finished. Otherwise it returns false

The following code shows how to Set the audio to loop:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<audio id="myAudio" controls loop>
  <source src="your.ogg" type="audio/ogg">
  <source src="your.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>//from   w w  w  . j ava  2  s.  c  om

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
    document.getElementById("myAudio").loop = true;
}
</script>

</body>
</html>

Related Tutorials