Horje

How to execute a JavaScript when an audio is ready to start playing

It will show up a popup that audio is ready to play.

index.html
Example: HTML
<!DOCTYPE html>
<html>
<body>
<script>
function myFunction() { alert("Can start playing audio");
}
</script>
<audio controls oncanplay="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>
</body>
</html>

Output should be:

How to execute a JavaScript when an audio is ready to start playing




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