HTMLMediaElement: play event

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

当 paused 属性由 true 转换为 false 时触发 play 事件,事件触发原因一般为 play() 方法调用,或者 autoplay 标签设置。

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

Examples

下方的例子监听了 HTMLMediaElement 标签的 play 事件,并且在事件触发后在控制台打印相应的信息。

Using addEventListener():

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

video.addEventListener('play', (event) => {
  console.log('The Boolean paused property is now false. Either the ' + 
  'play() method was called or the autoplay attribute was toggled.');
});

Using the onplay event handler property:

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

video.onplay = (event) => {
  console.log('The Boolean paused property is now false. Either the ' + 
  'play() method was called or the autoplay attribute was toggled.');
};

Specifications

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

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
play 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