html动态网页添加音频_将音频添加到网页

本文介绍了如何在HTML网页中添加音频,包括使音频可见、缓冲控制、编解码器支持、标记音频和辅助功能等方面,强调了正确设置MIME类型和适配不同浏览器的重要性。
摘要由CSDN通过智能技术生成

html动态网页添加音频

In principle, adding audio to a web page is quite straightforward. Assuming you have a standard mp3 file, just point the src attribute of the audio element to the file‘s location, just as you would in an img tag:

原则上,将音频添加到网页非常简单 。 假设您有一个标准的mp3文件,只需将audio元素的src属性指向该文件的位置即可,就像在img标签中一样

<audio src="03-ghosts-I.mp3">
</audio>

使音频可见 (Making Audio Visible)

However, that code doesn‘t result in anything visible on the page. The controls attribute must be added to the element to produce an audio control bar:

但是,该代码不会在页面上显示任何内容。 必须将controls 属性添加到元素以产生音频控制栏:

<audio src="03-ghosts-I.mp3" controls>
</audio>

The appearance of the control bar will differ between browsers, depending on the operating system. It‘s completely possible to craft your own UI for the audio element, but that requires writing some JavaScript.

在不同的浏览器中,控制栏的外观会有所不同,具体取决于操作系统。 完全可以为音频元素构建自己的UI ,但这需要编写一些JavaScript。

Note the lack of any value for the controls attribute. controls is an example of a “boolean” attribute: if the word controls, by itself, is present in the audio element, it has an effect; if not, the control bar is not shown. Formally, it’s also valid to write controls="controls", an approach that is still required when adding the attribute via JavaScript.

请注意,缺少controls属性的任何值。 controls是“布尔”属性的一个示例:如果audio元素中单独存在controls一词,则它具有效果; 如果不是, 则不显示控制栏。 正式

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值