Javascript DOM oncanplay Event

Introduction

Execute a JavaScript when a video is ready to start playing:

View in separate window

<!DOCTYPE html>
<html>
<body>

<video controls oncanplay="myFunction()">
  <source src="video.mp4" type="video/mp4">
  <source src="video.ogg" type="video/ogg">
  Your browser does not support HTML5 video.
</video>/*  www.  jav a  2  s.  c  om*/
<p id="demo"></p>
<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "Can start playing video";
}
</script>

</body>
</html>

The oncanplay event occurs when the browser can start playing the specified audio/video when it has buffered enough to begin.

Bubbles: No
Cancelable: No
Event type: Event
Supported HTML tags: <audio> and <video>
DOM Version: Level 3 Events



PreviousNext

Related