May 03, 2021 HTML5
2. To detect if your browser supports HTML5 video:
5. HTML5 (Video) - How it works
6. Video format with browser support
In this section, you'll learn how video works in HTML5, the video formats supported by mainstream browsers, and how to control video on a web page.
Many sites use video. HTML5 provides the standard for displaying video.
Until now, there was no standard for displaying video on a Web page.
Today, most videos are displayed through plug-ins such as Flash. However, not all browsers have the same plug-in.
HTML5 provides a standard way to include video through video elements.
Internet Explorer 9 Plus, Firefox, Opera, Chrome, and Safari support this element.
Note: Internet Explorer 8 or earlier versions of IE do not support the element.
To display a video in HTML5, all you need is:
The element provides playback, pause, and volume controls to control the video.
At the same time, the element also provides the width and height properties to control the size of the video. I f you set the height and width, the desired video space is preserved when the page loads. If you don't set these properties, the browser doesn't know the size of the video, the browser can no longer load when it retains a specific space, and the page changes depending on the size of the original video.
The content inserted between the label and the label is provided to browsers that do not support video elements.
The element supports multiple elements. E lements can link different video files. The browser will use the first recognizable format:
Currently, the elements support three video formats: MP4, WebM, and Ogg:
Browser | MP4 | WebM | Ogg |
---|---|---|---|
Internet Explorer 9+ | YES | NO | NO |
Chrome 6+ | YES | YES | YES |
Firefox 3.6+ | NO | YES | YES |
Safari 5+ | YES | NO | NO |
Opera 10.6+ | NO | YES | YES |
Format | MIME-type |
---|---|
MP4 | video/mp4 |
WebM | video/webm |
Ogg | video/ogg |
HTML5 and the elements also have methods, properties, and events.
The methods, properties, and events of the elements can be controlled using JavaScript.
Methods include playing, pausing, loading, and so on. P roperties such as length of time, volume, etc. can be read or set. One of the DOM events can notify you, for example, that the element starts playing, pauses, stops, and so on.
The simple method in the example shows us how to use the element, read and set properties, and how to call a method.
Create simple play/pause and resize controls for videos:
The example above calls two methods: play() and pause(). It uses two properties at the same time: paused and width.
Try it out . . .Label | describe |
---|---|
<video> | Define a video |
<source> | 定义多种媒体资源,比如<video> 和<audio> |
<track> | Define in the media player text trajectory |
HTML DOM Reference Manual: HTML DOM Video Object