首页 > 文章列表 > 我们如何在HTML中指定音频/视频在准备好后立即开始播放?

我们如何在HTML中指定音频/视频在准备好后立即开始播放?

HTML 视频播放 音频播放
109 2023-09-13

使用autoplay属性来设置音频或视频在页面加载时自动播放。

示例

您可以尝试运行以下代码来在HTML中实现autoplay属性:

<!DOCTYPE HTML>
<html>
   <body>
      <video width = "300" height = "200" controls autoplay>
         <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>
   </body>
</html>