html - 为什么浏览器不创建相应的 html 代码来打开音频文件

标签 html google-chrome specifications

如果您尝试在浏览器中打开音频文件,浏览器将创建以下代码:

<video controls autoplay name="media">
     <source src="https://stopmusic.net/_ld/65/6549_B.B.E-Seven_Day.mp3" type="audio/mp3">
</video>

他为什么使用 <video> 创建标记标签?

如果我们看一下 specification ,我们将看到以下内容:

When an image, video, or audio resource is to be loaded in a browsing context, the user agent should create a Document object, mark it as being an HTML document, set its content type to the computed MIME type of the resource (type in the navigate algorithm), initialize the Document object, append an html element to the Document, append a head element and a body element to the html element, append an element host element for the media, as described below, to the body element, and set the appropriate attribute of the element host element, as described below, to the address of the image, video, or audio resource.

enter image description here

正如您在浏览器中打开特定媒体文件时所看到的,浏览器会创建与其关联的特定代码。在这种情况下,由于某种原因,浏览器不会创建与之关联的代码。为什么会这样?这是实现规范错误吗?

最佳答案

我假设这是谷歌浏览器自主完成的事情,我觉得他们有自己的专有算法,将文件类型等同于特定标签,如 <video> , <audio><img> .我也会认为 .mp3文件将由 <audio> 打开标签,没有别的,因为它一个音频文件。在考虑了这些事情之后,这个特性将执行它在事物的生产端所做的事情是没有逻辑意义的。人们会假设任何以“mp4”扩展名结尾的文件都使用 <video>标签。我认为这是他们正在完成并决定无论如何都要推出的一项功能的主要示例,因为它有效并且不需要任何更多的努力。

关于html - 为什么浏览器不创建相应的 html 代码来打开音频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53790714/

相关文章:

javascript - 模式对话框中的 Jquery 问题

firefox - 浏览器添加 www.和 .com 自动到服务器地址

python - 从网页在服务器上启动 python 脚本

html - 导航栏中的 Bootstrap 4 导航丸

javascript - Protractor 未连接到 DevTools

iis - Chrome 无法显示 http 身份验证窗口

ruby-on-rails - minitest 没有拾取描述 block

php - 奇怪的字符^M php无法识别

c++ - 正式规范

html - 选择单选按钮时更改单选按钮标签颜色?