There are many ways to play videos in HTML. 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. The following HTML code displays the Flash video embedded in the web page: problem HTML4 does not recognize 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. The following HTML clip shows a Flash video embedded in a web page: 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. HTML5 The following HTML snippet shows a video in ogg, mp4, or webm format embedded in the web page: Question: You must convert the video to many different formats. Four different video formats are used in the following examples. HTML 5 Question: You have to convert the video to many different formats If a web page contains a hyperlink to a media file, most browsers use Auxiliary applications to play the file. The following code snippet shows a link to the AVI file. If the user clicks on the link, the browser will launch an “auxiliary application”, such as Windows Media Player, to play the AVI file: When video is included in a web page, it is called inline video. If you plan to use inline video in your web application, you need to be aware that many people find inline video exasperating. Also note that the user may have turned off the inline video option in the browser. Our best advice is to include them only where users want to see inline videos. A positive example is that when a user needs to see a video and click on a link, the page opens and the video is played. New: new HTML5 tag. 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 ¶
11.53.3. Use
<embed>
label ¶
<embed>
the role of tags is to embed multimedia elements in HTML pages.Example ¶
<embed src="intro.swf" height="200" width="200">
<embed>
label. Your page failed validation. 11.53.4. Use the < object > tag ¶
<object>
The role of tags is to embed multimedia elements in HTML pages.Example ¶
<object data="intro.swf" height="200" width="200"></object>
11.53.5. Use the HTML5 < video > element ¶
<video>
the tag defines a video or movie.
<video>
elements are supported in all modern browsers.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>
<video>
the element is not valid in older browsers. 11.53.6. The best HTML solution ¶
<video>
the element attempts to play the video in one of the mp4, ogg, or webm formats. If both fail, fall back to
<embed>
element. 11.53.7. HTML 5 + < object > + < embed > ¶
<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>
11.53.8. Use hyperlinks ¶
Example ¶
<a href="intro.swf">Play a video file</a>
11.53.9. Instructions on inline video ¶
11.53.10. HTML multimedia tags ¶