Horje

How to execute a JavaScript when a video is ready to start playing

It will show up a popup that video can start.

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

<script>
function myFunction() {
  alert("Can start playing video");
}
</script>

<video controls oncanplay="myFunction()">
  <source src="https://download.samplelib.com/mp4/sample-5s.mp4" type="video/mp4">
  <source src="https://download.samplelib.com/mp4/sample-5s.mp4" type="video/ogg">
  Your browser does not support HTML5 video.
</video>

<p>Video courtesy of <a href="https://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>


</body> 
</html>

Output should be:

How to execute a JavaScript when a video is ready to start playing



Single Articles
Example of HTML oncanplay Event AttributeMedia Events Attribute
Definition and Usage of HTML oncanplay Event AttributeMedia Events Attribute
Browser Support of HTML oncanplay Event AttributeMedia Events Attribute
Syntax of HTML oncanplay Event AttributeMedia Events Attribute
Attribute Values of HTML oncanplay Event AttributeMedia Events Attribute
Technical Details of HTML oncanplay Event AttributeMedia Events Attribute
How to execute a JavaScript when a video is ready to start playingMedia Events Attribute
How to execute a JavaScript when an audio is ready to start playingMedia Events Attribute


Related Articles
List of Media Events Media Events Attribute
HTML onabort Event Attrribute Media Events Attribute
HTML oncanplay Event Attribute Media Events Attribute
HTML oncanplaythrough Event Attribute Media Events Attribute
HTML ondurationchange Event Attribute Media Events Attribute
HTML onended Event Attribute Media Events Attribute

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