怎么在html中插入视频和音频

lxf2023-03-10 17:35:01

怎么在html中插入视频和音频

插入视频的理想解决方法

HTML5 + <object> + <embed>

(视频教程推荐:html视频教程)

代码如下:

<!DOCTYPE html>
<html>
<body>

<video width="320" height="240" controls="controls" autoplay="autoplay">
  <source src="/i/movie.ogg" type="video/ogg" />
  <source src="/i/movie.mp4" type="video/mp4" />
  <source src="/i/movie.webm" type="video/webm" />
  <object data="/i/movie.mp4" width="320" height="240">
    <embed width="320" height="240" src="/i/movie.swf" />
  </object>
</video>

</body>
</html>

插入音频的理想解决方法:

<embed>

下面的例子使用了两个不同的音频格式。Html5 <audio> 元素会尝试以 mp3 或 ogg 来播放音频。如果失败,代码将回退尝试 <embed> 元素。

<!DOCTYPE HTML>
<html>
<body>

<audio controls="controls">
  <source src="/i/song.ogg" type="audio/ogg">
  <source src="/i/song.mp3" type="audio/mpeg">
<embed height="100" width="100" src="/i/song.mp3" />
</audio>

</body>
</html>

相关推荐:html教程

以上就是怎么在html中插入视频和音频的详细内容,更多请关注AdminJS其它相关文章!