HTML Video (Videos) Play
There are many ways to play the video in HTML method.
HTML Video (Videos) Play
Examples
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
<source src="movie.webm" type="video/webm">
<object data="movie.mp4" width="320" height="240">
<embed src="movie.swf" width="320" height="240">
</object>
</video>
try it"
Problems and solutions
Play Video in HTML is not easy!
You need a lot of familiar tips to ensure that your video file in all browsers (Internet Explorer, Chrome, Firefox, Safari, Opera), and all hardware (PC, Mac, iPad, iPhone) can be played.
In this chapter, W3CSchool you summarize the problems and solutions.
Using the <embed> tag
Role <embed> tag is to embed multimedia elements in HTML pages.
The following HTML code to display Flash video embedded in the page:
problem
- HTML4 does not recognize the <embed> tag. Your page can not be verified.
- If your browser does not support Flash, so the video will not play
- iPad and iPhone can not display Flash videos.
- If you convert videos to other formats, it still does not play in all browsers.
Using the <object> tag
Role <object> tag is to embed multimedia elements in HTML pages.
The following HTML snippet shows some Flash video embedded in the page:
problem:
- If your browser does not support Flash, the video will not play.
- iPad and iPhone can not display Flash videos.
- If you convert videos to other formats, it still does not play in all browsers.
Using the HTML5 <video> element
HTML5 <video> tag defines a video or movie.
<Video> element in all modern browsers are supported.
The following HTML fragment will display a web page embedded ogg, mp4, or webm format video:
Examples
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
<source src="movie.webm" type="video/webm">
您的浏览器不支持 video 标签。
</video>
try it"
problem:
- You need to convert video into many different formats.
- <Video> element is not valid in older browsers.
Best HTML Solution
The following example uses four different video formats. HTML 5 <video> element tries to play mp4, ogg, or webm formats is to play the video. If all fails, then fall back to <embed> element.
HTML 5 + <object> + <embed>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
<source src="movie.webm" type="video/webm">
<object data="movie.mp4" width="320" height="240">
<embed src="movie.swf" width="320" height="240">
</object>
</video>
try it"
problem:
- You must convert many different video formats
Youku Solutions
The easiest way to display videos in HTML is to use Youku and other video sites.
If you want to play video in a web page, you can upload a video to Youku and other video sites, and then insert the HTML code to play the video in your page:
Using hyperlinks
If the page contains a hyperlink pointing to media files, most browsers will use "helper application" to play the file.
The following code fragment shows links to AVI file. If the user clicks on the link, the browser will start the "Helper Applications", such as Windows Media Player to play the AVI file:
On inline video description
When a video is included in the web page, it is called inline video.
If you plan to use inline video in a web application, you need to realize that many people find inline videos annoying.
Also note that users may have closed your browser inline video option.
Our best advice is to only when the user wants to see the place inline video contains them. A positive example is that when the user needs to see the video and click on a link will open the page and play the video.
HTML multimedia tag
New: HTML5 new tags.
标签 | 描述 |
---|---|
<embed> | 定义内嵌对象。HTML4 中不赞成,HTML5 中允许。 |
<object> | 定义内嵌对象。 |
<param> | 定义对象的参数。 |
<audio> New | 定义了声音内容 |
<video> New | 定义一个视频或者影片 |
<source> New | 定义了media元素的多媒体资源(<video> 和 <audio>) |
<track> New | 规定media元素的字幕文件或其他包含文本的文件 (<video> 和<audio>) |