Horje

How to Run "myFunction" when the audio has finished playing

Audio Example. Play the audio file: This example demonstrates how to use the "onended" attribute on an AUDIO element.
index.html
Example: HTML
<audio id="myAudio" controls onended="myFunction()">
  <source src="https://download.samplelib.com/mp3/sample-3s.mp3" type="audio/ogg">
  <source src="https://download.samplelib.com/mp3/sample-3s.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

<p>Play the audio file:</p>

<script>
function myFunction() {
  alert("Thank you for listening");
}
</script>

Output should be:

How to Run "myFunction" when the audio has finished playing




Type:
html
Category:
Web Tutorial
Sub Category:
HTML Attribute
Uploaded by:
Admin