Supports HTML MP4

Play HTML video (videos)

There are many ways to play the video in HTML.


Play HTML video (videos)

Examples

<video width="320" height="240" controls>
<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>

To attempt "


Problems and solutions

Playing video in HTML is not easy!

You need many well-known tips to ensure that your video file can be played in all browsers (Internet Explorer, Chrome, Firefox, Safari, Opera) and all hardware (PC, Mac, iPad, iPhone).

In this chapter you will summarize the problems and solutions of W3CSchool.


With the tag

Role tag is used to embed multimedia elements in HTML pages.

The following HTML code will display Flash videos embedded in the page:

Examples

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

To attempt "

problem

  • HTML4 does not recognize the tag. Your page cannot be verified.
  • If your browser does not support Flash, the video will not play
  • iPad and iPhone cannot display Flash videos.
  • When you convert videos to other formats, it still won't play in all browsers.

With the tag

Role tag is for embedding multimedia elements in HTML pages.

The following HTML code snippet shows some Flash videos embedded in the page:

Examples

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

To attempt "

Problem:

  • If your browser doesn't support Flash, the video won't play.
  • iPad and iPhone cannot display Flash videos.
  • When you convert videos to other formats, it still won't play in all browsers.

With the HTML5

HTML5

The following html fragment will be embedded in a web page ogg, mp4 or webm format video display:

Examples

<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
<source src="movie.webm" type="video/webm">
您 的 浏览 器 不 支持 video 标签。
</video>

To attempt "

Problem:

  • You need to convert video to many different formats.

Best HTML solution

The following example uses four different video formats. HTML 5

HTML 5 + +
<video width="320" height="240" controls>
<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>

To attempt "

Problem:

  • You have to have 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 video to play in a web page, you can upload a video to Youku and other video websites and then paste the HTML code to play the video in the page:

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

With hyperlinks

If the page contains a hyperlink to media files, most browsers will use "helper programs" to play the file.

The following code fragment shows links to AVI file. When the user clicks the link, the browser will launch the "utilities" such as Windows Media Player to play the AVI file:

Examples

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

To attempt "


On inline video description

When a video is included on 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 video annoying.

Also note that users have closed their browsers inline video option.

Our best advice is only when the user wishes to see the inline video it contains. A positive example is that when the user needs to view the video and click a link, open the page and play the video.


HTML multimedia tag

New: HTML5 new tags.