HTML Audio/Video DOMcanplayEvents

HTML Audio/Video DOM Reference Manual

Example

Indicates that this video is ready to start playing:

myVid=document.getElementById("video1");
myVid.oncanplay=alert("Can start playing video");

Try it Yourself »

Definition and Usage

When the browser is able to start playing the specified audio/video, the canplay event occurs.

When the audio/video is in the process of loading, the following events occur in sequence:

  1. loadstart
  2. durationchange
  3. loadedmetadata
  4. loadeddata
  5. progress
  6. canplay
  7. canplaythrough

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the canplay event.

Note:Internet Explorer 8 and earlier versions do not support this event.


Syntax

In HTML:

<audio|video oncanplay="SomeJavaScriptCode">

In JavaScript:

audio|video.oncanplay=SomeJavaScriptCode;

Using addEventListener():

audio|video.addEventListener("canplay", function()
  {
  //SomeJavaScriptCode
  }
);

Technical Details

The following HTML tags are supported: <audio>, <video>
The following JavaScript objects are supported: Audio, Video


实例

More Examples

Using the oncanplay attribute on HTML elements

Using addEventListener() to listen for the canplay event


HTML Audio/Video DOM Reference Manualother extensions