Execute a JavaScript when a video has started to play:
This example demonstrates how to assign an "onplay" event to a video element.
<!DOCTYPE html> <html> <body> <p>Press play.</p> <video controls onplay="myFunction()"> <source src="video.mp4" type="video/mp4"> <source src="video.ogg" type="video/ogg"> Your browser does not support HTML5 video. </video>//from w w w . ja v a2s . c o m <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = "The video has started to play"; } </script> </body> </html>
The onplay event occurs when the audio/video has been started or is no longer paused.
The onpause event occurs when the audio/video has been paused.
Bubbles: | No |
---|---|
Cancelable: | No |
Event type: | Event |
Supported HTML tags: | <audio> and <video> |