Latest web development tutorials

HTML Audio / Video DOM play event

HTML audio / video Tag Reference HTML Audio / Video DOM Reference

Examples

When the video starts playing pop-up message:

var vid = document.getElementById ( "myVideo");
vid.onplay = function () {
alert ( "The video has started to play");
};

try it"

Bottom of this article contains more examples.


Definition and Usage

play event is triggered when the audio / video (audio / video) to start playback.

Tip: PAUSE trigger event in the audio / video (audio / video) to pause playback.


Browser Support

Figures in the table represent the first browser to support this version of events.

event
play Yes 9.0 Yes Yes Yes


grammar

In HTML:

<Audio | video onplay = "myScript "> try

In JavaScript:

audio | video .onplay = function () {myScript}; try

JavaScript, use the addEventListener () method:

audio | video .addEventListener ( "play" , myScript); try

Note: Internet Explorer 8 and earlier versions of IE do not support addEventListener () method.


technical details
Supported HTML tags: <Audio> and <video>
Supported JavaScript Objects: Audio, Video


Examples

More examples

Examples

When an audio message starts playing pop:

var aud = document.getElementById ( "myAudio");
aud.onplay = function () {
alert ( "The audio has started to play");
};

try it"


HTML audio / video Tag Reference HTML Audio / Video DOM Reference