在以HTML加载媒体数据时执行脚本?

加载媒体数据时,请使用onloaddata事件执行脚本。您可以尝试运行以下代码来实现onloaddata事件-

示例

视频加载后,以下代码会生成一个警告框-

<!DOCTYPE html>
<html>
   <body>
      <video controls onloadeddata = "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("Loaded!");
         }
      </script>
   </body>
</html>