Zdarzenie ondurationchange

Definition and Usage

The ondurationchange event occurs when the duration of the audio/video changes.

Note:After the audio/video is loaded, the duration will change from "NaN" to the actual duration of the audio/video.

During the loading process of audio/video, the following events will occur in the following order:

  1. onloadstart
  2. ondurationchange
  3. onloadedmetadata
  4. onloadeddata
  5. onprogress
  6. oncanplay
  7. oncanplaythrough

Example

Example 1

Execute JavaScript When Video Duration Changes:

<video ondurationchange="myFunction()">

Try It Yourself

Example 2

Execute JavaScript When Audio Begins to Load:

<audio ondurationchange="myFunction()">

Try It Yourself

Syntax

In HTML:

<element ondurationchange="myScript">

Try It Yourself

In JavaScript:

object.ondurationchange = function(){myScript};

Try It Yourself

In JavaScript, use the addEventListener() method:

object.addEventListener("durationchange", myScript);

Try It Yourself

Note:Internet Explorer 8 or earlier versions do not support addEventListener() Method.

Technical Details

Bubbling: Not Supported
Cancelable: Not Supported
Event Type: Event
Supported HTML Tags: <audio> and <video>
DOM Version: Level 3 Events

Browser Support

The numbers in the table indicate the first browser version that fully supports this incident.

Incident Chrome IE Firefox Safari Opera
ondurationchange Wsparcie 9.0 Wsparcie Wsparcie Wsparcie