11.53. HTML Video

发布时间 : 2025-10-25 13:33:12 UTC      

Page Views: 10 views

There are many ways to play videos in HTML.

11.53.1. HTML video (Videos) playback

Example

<videowidth="320"height="240"controls><sourcesrc="movie.mp4"type="video/mp4"><sourcesrc="movie.ogg"type="video/ogg"><sourcesrc="movie.webm"type="video/webm"><objectdata="movie.mp4"width="320"height="240"><embedsrc="movie.swf"width="320"height="240">object>video>      

11.53.2. Problems and solutions

Playing videos in HTML is not easy!

You need to be familiar with a lot of tricks to ensure that your video files can be played in all browsers (Internet Explorer, Chrome, Firefox, Safari, Opera) and on all hardware (PC, Mac, iPad, iPhone).

In this chapter, the rookie tutorial summarizes the problems and solutions for you.

11.53.3. Use label

the role of tags is to embed multimedia elements in HTML pages.

The following HTML code displays the Flash video embedded in the web page:

Example

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

problem

  • HTML4 does not recognize label. Your page failed validation.

  • If the browser does not support Flash, the video will not be played

  • IPad and iPhone cannot display Flash video.

  • If you convert the video to another format, it still won’t play in all browsers.

11.53.4. Use the < object > tag

The role of tags is to embed multimedia elements in HTML pages.

The following HTML clip shows a Flash video embedded in a web page:

Example

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

Question:

  • If the browser does not support Flash, the video cannot be played.

  • IPad and iPhone cannot display Flash video.

  • If you convert the video to another format, it still won’t play in all browsers.

11.53.5. Use the HTML5 < video > element

HTML5

The following HTML snippet shows a video in ogg, mp4, or webm format embedded in the web page:

Example

<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"> Your browser does not support video tags. video>    

Question: