HTMLMediaElement: canplaythrough

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

canplaythrough 事件在终端可以播放媒体文件时(估计已经加载了足够的数据来播放媒体直到其结束,而不必停止以进一步缓冲内容)被触发。

是否冒泡
是否可取消
接口 Event
目标 元素
默认行为
事件处理器属性 GlobalEventHandlers.oncanplaythrough

示例

以下示例展示了如何为媒体元素的 canplaythrough 事件添加一个事件监听器,以在该事件触发时发送一条消息。

使用 addEventListener()

js
const video = document.querySelector("video");

video.addEventListener("canplaythrough", (event) => {
  console.log(
    "I think I can play through the entire " +
      "video without ever having to stop to buffer.",
  );
});

使用 oncanplaythrough 事件处理器属性:

js
const video = document.querySelector("video");

video.oncanplaythrough = (event) => {
  console.log(
    "I think I can play through the entire " +
      "video without ever having to stop to buffer.",
  );
};

规范

Specification
HTML Standard
# event-media-canplaythrough
HTML Standard
# handler-oncanplaythrough

浏览器兼容性

BCD tables only load in the browser

相关事件

参见