×

了解下HTML5的内嵌媒体

作者:cidy20172017.11.07来源:Web前端之家浏览:12472评论:0
关键词:HTML5媒体

视频已经在 Web 上广泛流行了,但是其格式几乎都是专有的。YouTube 使用 Flash,Microsoft 使用 Windows Media®,Apple 使用 QuickTime。在一种浏览器中用来嵌入这些内容的标记在另一种浏览器中是无效的。因此,WhatWG 提议引入一个新的 video 元素,用来嵌入任意视频格式。例如,可以用以下代码嵌入我的 QuickTime 电影 “a Sora in Prospect Park”:
<video src="http://www.cafeaulait.org/birds/sora.mov" />  
对于以哪种格式和解码器作为首选,仍然有争议。可能会强力推荐或要求使用 Ogg Theora。还可以可选地支持 QuickTime 等专有格式和 MPEG-4 等受专利限制的格式。实际使用的格式很可能由市场决定,就像是 GIF、JPEG 和 PNG 格式那样(这些格式通过市场竞争压倒了 BMP、X-Bitmap 和 JPEG 2000 等竞争者,成为 img 元素的首选格式)。
还提议引入 audio 元素。例如,可以使用以下代码给 Web 页面加上背景音乐:
<audio src="spacemusic.mp3" autoplay="autoplay" loop="20000" />  
autoplay 属性指示浏览器在装载页面后立即开始播放,而不等待明确的用户请求。音频循环播放 20,000 次,然后停止(或者在用户关闭窗口或转到另一个页面时停止)。当然,浏览器可以(而且应该)允许用户关闭内嵌的媒体,不应该只按页面作者的要求去做。
浏览器必须支持 WAV 格式,还可以支持 MP3 等其他格式。
因为老式浏览器不支持这些元素,而且它们对于盲人和聋人用户来说没有意义,所以 audio 和 video 元素可以包含额外的标记,用来描述音频和视频的内容。这对搜索引擎也有帮助。在理想情况下,这些标记是音频和视频内容的完整文字版本。例如,代码8 显示 用 HTML 5 编写的 John F. Kennedy 的就职演说。

<audio src="kennedyinauguraladdrees.mp3">
 
<p>
 
Vice President Johnson, Mr. Speaker, Mr. Chief Justice,
 
President Eisenhower, Vice President Nixon, President Truman,
 
Reverend Clergy, fellow citizens:
 
</p>
 
<p>
 
We observe today not a victory of party, but a celebration of
 
freedom -- symbolizing an end, as well as a beginning --
 
signifying renewal, as well as change. For I have sworn before
 
you and Almighty God the same solemn oath our forebears
 
prescribed nearly a century and three-quarters ago.
 
</p>
 
<p>
 
The world is very different now. For man holds in his mortal
 
hands the power to abolish all forms of human poverty and all  
 
forms of human life. And yet the same revolutionary beliefs for
 
which our forebears fought are still at issue around the globe --
 
the belief that the rights of man come not from the
 
generosity of the state, but from the hand of God.
 
</p>
 
<p>
 
...
 
</p>
 
</audio>

您的支持是我们创作的动力!
温馨提示:本文作者系 ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://www.jiangweishan.com/article/HTML5SDFSDJF123123.html

网友评论文明上网理性发言 已有0人参与

发表评论: