Horje

How to Run "myFunction" when the audio file is being played - HTML onplaying Attribute

Audio Example. This example demonstrates how to use the "onplaying" attribute on an AUDIO element.

index.html
Example: HTML
<!DOCTYPE html> 
<html> 
<body> 

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

<audio id="myAudio" controls onplaying="myFunction()">
  <source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/ogg">
  <source src="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

<script>
function myFunction() {
  alert("The audio file has started playing");
}
</script> 

<p>This example demonstrates how to use the "onplaying" attribute on an AUDIO element.</p>

</body> 
</html>

Output should be:

How to Run "myFunction" when the audio file is being played - HTML onplaying Attribute




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