Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML Audio/Video DOM play Event

HTML Audio/Video DOM play Event

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

Example

Display a message when the video starts playing:

var vid = document.getElementById("myVideo");

vid.onplay = function() {

    alert("The video has started to play");

};

Try it »

The bottom of this article contains more examples.


Definition and Usage

The play event is triggered when the audio/video starts playing.

Tip: pause The event is triggered when the audio/video is paused.


Browser support

The numbers in the table indicate the version number of the first browser to support the event.

Events
play Yes 9.0 Yes Yes Yes

Syntax

In HTML:

<

audio|video

onplay="

myScript

">

Try it

In JavaScript:

audio|video

.onplay=function(){

myScript

};

Try it

In JavaScript, use the addEventListener() method:

audio|video

.addEventListener("play",

myScript

);

Try it

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


Technical Details

Supported HTML tags:
Supported JavaScript objects: Audio, Video

More examples

Example

Display a message when the audio starts playing:

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