HTML Audio/Video DOM playEvents
HTML Audio/Video DOM Reference Manual
Example
Display a prompt message when the video starts playing:
var vid = document.getElementById("myVideo");
vid.onplay = function() {
alert("The video has started to play");
};
vid.onplay = function() {
alert("The video has started to play");
};
Try it Yourself »
This article contains more examples at the bottom.
Definition and Usage
The play event is triggered when the audio/video begins playing.
Tip: pauseThe event is triggered when the audio/video is paused.
Browser Support
The numbers in the table indicate the version number of the first browser that supported the event.
| Events | |||||
|---|---|---|---|---|---|
| play | Yes | 9.0 | Yes | Yes | Yes |
Syntax
In HTML:
<audio|video onplay="myScript">Try it Yourself
In JavaScript:
audio|video.onplay=function(){myScript};Try it Yourself
In JavaScript, using the addEventListener() method:
audio|video.addEventListener("play", myScript);Try it Yourself
Note:Internet Explorer 8 and earlier IE versions are not supportedaddEventListener()method.
Technical Details
| Supported HTML tags: | <audio> and <video> |
|---|---|
| Supported JavaScript objects: | Audio, Video |

More Examples
Example
Display a prompt message when the audio starts playing:
var aud = document.getElementById("myAudio");
aud.onplay = function() {
alert("The audio has started to play");
};
aud.onplay = function() {
alert("The audio has started to play");
};
Try it Yourself »
HTML Audio/Video DOM Reference Manualother extensions