您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

HTML 视频 Videos

在 html 中播放视频的有很多种

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

问题以及

在 HTML 中播放视频并不容易

需要谙熟大量技巧,以确保视频在所有浏览器中(Internet Explorer,Chrome,Firefox,Safari,Opera)和所有硬件上(PC,Mac,iPad,iPhone)都能够播放

本节,我们就来介绍在 HTML 中嵌入视频碰到的问题和办法。

使用 <embed>

<embed> 的作用是在 HTML 中嵌入多媒体元素

下面的 HTML 嵌入网页的 Flash 视频

<embed src="intro.swf" height="200" width="200">

HTML4 无法识别 <embed> ,无法通过验证

如果浏览器 Flash,那么视频将无法播放

iPad 和 iPhone 不能 Flash 视频

如果您将视频转换为其他格式,那么它仍然不能在所有浏览器中播放

使用 <object>

<object> 的作用是在 HTML 中嵌入多媒体元素

下面的 HTML 片段嵌入网页的一段 Flash 视频

<object data="/static/i/html/intro.swf" height="200" width="200"></object>

如果浏览器 Flash,将无法播放视频

iPad 和 iPhone 不能 Flash 视频

如果您将视频转换为其他格式,那么它仍然不能在所有浏览器中播放

使用 HTML5 <video> 元素

HTML5 <video> 定义了视频或者影片

<video> 元素在所有现代浏览器中都

以下 HTML 片段会一段嵌入网页的 ogg、mp4 或 webm 格式的视频

<video width="320" height="240" controls>
  <source src="/static/i/html/html_video_1. mp4" type="video/mp4">
  <source src="/static/i/html/html_video_1.ogg" type="video/ogg">
  <source src="/static/i/html/html_video_1.webm" type="video/webm">
</video>

必须把视频转换为很多不同的格式

<video> 元素在老式浏览器中无效

最好的 HTML

下面的范例中使用了 4 中不同的视频格式

HTML 5 <video> 元素会尝试播放以 mp4、ogg 或 webm 格式中的一种来播放视频

如果均失败,则回退到 <embed> 元素

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

必须把视频转换为很多不同的格式

优酷案

在 HTML 中视频的最简单的是使用优酷等视频网站。

如果希望在网页中播放视频,那么可以把视频到优酷等视频网站,然后在您的网页中插入 HTML 即可播放视频

<embed src="http://player.youku.com/player./sid/XMzI2NTc4NTMy/v.swf" width="480" height="400" type="application/x-shockwave-flash">
</embed>

使用超

如果网页包含指向媒体的超,大多数浏览器会使用"辅助应用程序"来播放

以下片段指向 AVI 的

如果点击该,浏览器会启动"辅助应用程序",比如 Windows Media Player 来播放这个 AVI

<a href="/static/i/html/intro.swf">Play a video file</a>

关于内联视频的说明

当视频被包含在网页中时,它被称为内联视频

如果打算在 web 应用程序中使用内联视频,需要意识到很多人都觉得内联视频令人恼火

同时请注意,可能已经了浏览器中的内联视频选项

所以我们建议只在希望看到内联视频的地方包含它们

正面的例子是,在需要看到视频并点击某个时,会打开然后播放视频。


联系我
置顶