HTMLMediaElement: durationchange 事件

翻译不完整。 请帮助我们翻译这篇文章!

durationchange 事件会在 duration 属性更新时被触发。

Bubbles No
Cancelable No
Interface Event
Target Element
Default Action None
Event handler property GlobalEventHandlers.ondurationchange
Specification HTML5 media

例子

下面的例子为 HTMLMediaElement 的 durationchange  事件添加事件监听器,然后在事件触发时发送一个消息。

使用 addEventListener():

const video = document.querySelector('video');

video.addEventListener('durationchange', (event) => {
  console.log('Not sure why, but the duration of the video has changed.');
});

使用 ondurationchange 事件处理器属性:

const video = document.querySelector('video');

video.ondurationchange = (event) => {
  console.log('Not sure why, but the duration of the video has changed.');
};

Specifications

Specification Status
HTML Living Standard
durationchange media event
Living Standard
HTML5
durationchange media event
Recommendation

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
durationchange eventChrome Full support 3Edge Full support 12Firefox Full support 3.5IE Full support 9Opera Full support 10.5Safari Full support 3.1WebView Android Full support YesChrome Android Full support 18Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support 1.0

Legend

Full support  
Full support

See Also