How to insert video into HTML and make it compatible with all browsers

How to insert video into HTML and make it compatible with all browsers
There are two most commonly used methods to insert videos into HTML, one is the old <object></object> tag, and the other is the <video></video> tag in HTML5.

The compatibility of the former is impeccable, but it is not very convenient to use. The latter is very convenient to use, but the compatibility is a headache.

Although the latter has many compatibility issues, it is very convenient to use and in line with the future development trend of web design. Therefore, we use the latter as the main method to insert videos. Because of its compatibility issues, the former is used as an auxiliary method.

Here is an example:

Copy code
The code is as follows:

<video width="602px" height="345px" controls="controls">
<source src="public/video/test.mp4" type="video/mp4"></source>
<source src="public/video/test.ogg" type="video/ogg"></source>
your browser does not support the video tag
</video>

Currently, the video element supports three video formats:
Format IE Firefox Opera Chrome Safari
Ogg No 3.5+ 10.5+ 5.0+ No
MPEG 4 9.0+ No No 5.0+ 3.0+
WebM No 4.0+ 10.6+ 6.0+ No

Ogg = Ogg file with Theora video codec and Vorbis audio codec

MPEG4 = MPEG 4 files with H.264 video encoding and AAC audio encoding

WebM = WebM files with VP8 video encoding and Vorbis audio encoding

Note: The format must meet the three detailed requirements above, such as MPEG 4, must be H.264 video and AAC audio.

In this case, if the video format is correct, we are satisfied with the compatibility results of most browsers, but IE678 does not support it, and their users are still a very large group in China, so we must think of another solution to support them:

Copy code
The code is as follows:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="624" height="351" style="margin-top: -10px;margin-left: -8px;" id="FLVPlayer1">
<param name="movie" value="FLVPlayer_Progressive.swf" />
<param name="quality" value="high" />
<param name="wmode" value="opaque" />
<param name="scale" value="noscale" />
<param name="salign" value="lt" />
<param name="FlashVars" value="&amp;MM_ComponentVersion=1&amp;skinName=public/swf/Clear_Skin_3&amp;streamName=public/video/test&amp;autoPlay=false&amp;autoRewind=false" />
<param name="swfversion" value="8,0,0,0" />
<!-- This param tag prompts users of Flash Player 6.0 r65 and later to download the latest version of Flash Player. If you don't want users to see this prompt, remove it. -->
<param name="expressinstall" value="expressInstall.swf" />
</object>

Some files are introduced here. In addition to the flv format video, there are also several swf or js files, all of which are generated by DW software. Friends who don’t want to study the <object></object> tags can use DW software to generate them. If you can cleverly integrate

These two pieces of code can get the ultimate code that is compatible with all major browsers.

So we can do this:

Use jQuery to determine whether the browser is IE (no need to determine the specific IE version, because the server may not pass the higher version of IE, temporarily all IE uses <object></object> tags), load different tags according to the version, the code is as follows:

Copy code
The code is as follows:

<script>
if($.browser.msie){
document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="624" height="351" style="margin-top: -10px;margin-left: -8px;" id="FLVPlayer1">'+
'<param name="movie" value="FLVPlayer_Progressive.swf" />'+
'<param name="quality" value="high" />'+
'<param name="wmode" value="opaque" />'+
'<param name="scale" value="noscale" />'+
'<param name="salign" value="lt" />'+
'<param name="FlashVars" value="&amp;MM_ComponentVersion=1&amp;skinName=public/swf/Clear_Skin_3&amp;streamName=public/video/test&amp;autoPlay=false&amp;autoRewind=false" />'+
'<param name="swfversion" value="8,0,0,0" />'+
'<!-- This param tag prompts users of Flash Player 6.0 r65 and later to download the latest version of Flash Player. If you don't want users to see this prompt, remove it. -->'+
'<param name="expressinstall" value="expressInstall.swf" />'+
'</object>');
}else{
document.write('<video width="602px" height="345px" controls="controls">'+
'<source src="public/video/test.mp4" type="video/mp4"></source>'+
'<source src="public/video/test.ogg" type="video/ogg"></source>'+
'your browser does not support the video tag'+
'</video>');
}
</script>

Don't forget to import the jquery file before writing this code

At this point, you can write HTML video code that is compatible with all browsers.

<<:  Detailed process of installing logstash in Docker

>>:  Reference SVG images in CSS to support dynamic color switching implementation code

Recommend

Example of how rem is adapted for mobile devices

Preface Review and summary of mobile terminal rem...

JavaScript basics for loop and array

Table of contents Loop - for Basic use of for loo...

Tips for importing csv, excel or sql files into MySQL

1. Import csv file Use the following command: 1.m...

Detailed examples of Docker-compose networks

Today I experimented with the network settings un...

WeChat applet implements a simple calculator

A simple calculator written in WeChat applet for ...

Version numbers in css and js links in HTML (refresh cache)

background Search the keyword .htaccess cache in ...

Remote development with VSCode and SSH

0. Why do we need remote development? When develo...

A brief talk about the diff algorithm in Vue

Table of contents Overview Virtual Dom principle ...

js implements single click to modify the table

Pure js implements a single-click editable table ...

Detailed explanation of virtual DOM and diff algorithm in react

The role of virtual DOM First of all, we need to ...

Detailed explanation of Getter usage in vuex

Preface Vuex allows us to define "getters&qu...

Linux CentOS 6.5 Uninstall, tar and install MySQL tutorial

Uninstall the system-provided MySQL 1. Check whet...

Sample code for implementing PC resolution adaptation in Vue

Table of contents plan Install Dependencies Intro...

Theory: The two years of user experience

<br />It has been no more than two years sin...

How to use Dockerfile to create a mirror of the Java runtime environment

The current environment is: Centos 7.5 docker-ce ...