媒体开始播放时在 HTML 中执行脚本?


使用 oncanplay 属性来定义音频/视频准备开始播放的时间。

示例

你可以尝试运行以下代码以了解如何在媒体准备开始播放时执行脚本 -

<!DOCTYPE html>
<html>
   <body>
      <video id = "myid" width = "320" height = "176" controls oncanplay="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("Video loaded!");
         }
      </script>
   </body>
</html>

更新时间:30-5-2020

123 次阅读

开启您的 职业生涯

通过完成本课程并获得认证

开始
广告
© . All rights reserved.