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

htmlweb developmentfront end technology更新于 2025/8/14 15:40:17

使用 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>

相关文章


有用资源