当文件可以一直播放到最后而无需暂停HTML缓冲时执行脚本?

当文件可以一直播放到最后而无需暂停HTML缓冲时,请使用oncanplaythrough 属性执行脚本。

示例

您可以尝试运行以下代码以实现oncanplaythrough 属性-

<!DOCTYPE html>
<html>
   <body>
      <video id = "myVideo" width = "400" height = "200" controls oncanplaythrough = "display()">
         <source src = "/html5/foo.ogg" type = "video/ogg" />
         <source src = "/html5/foo.mp4" type = "video/mp4" />
         Your browser does not support the video element.
      </video>
      <script>
         function display() {
            alert("可以播放而无需暂停缓冲。");
         }
      </script>
   </body>
</html>