Home Web Front-end H5 Tutorial HTML5 video method to achieve browser compatibility

HTML5 video method to achieve browser compatibility

Dec 04, 2017 am 11:55 AM
firefox video webkit

In this article, we will share with you how to achieve browser compatibility for HTML5 video. In the past, flash was the best way to solve videos on web pages. As of now, it is still mainstream, such as those video websites such as Youku and Xiami. Such online music websites still use flash to provide playback services. But this situation will change with the development of HTML5. As far as video is concerned, HTML5 adds video to implement the function of playing videos online.

Using HTML5 video, you can easily use JavaScript to control the video content, etc. The function is very powerful, and the code is relatively small to speed up the loading speed. In addition, cross-platform is relatively good, especially some tablets, mobile phones, etc. For example, Apple's products do not support flash and only support the video function in HTML5.

But the compatibility issue of HTML5 is a flaw. We can use video to play videos on web pages, but visitors using early browsers may not be able to watch this video normally. In addition, due to the historical origin of video encoders, various browsers support different video formats. To deal with these problems and want to use the HTML5 video function in web pages, you can follow the following three steps.

Step one: Prepare multi-format video files in advance

Due to the copyright issue of the encoder, different browsers have different compatibility with video formats. Currently, no video format is compatible with all browsers, and the only solution is to convert the video into multiple formats.

First, prepare a video in mp4 format, which can be used on Apple devices; secondly, prepare a video in ogv format, which can be used in Firefox; finally, prepare a video in webm format, which can be used on Google Chrome, etc. Webm was proposed by Google. It is open source, free, and is likely to become a video format compatible with all browsers.

The trouble with preparing a multi-format browser is converting the formats. Domestic video conversion tools have relatively few functions, the conversion format may not be as good as the last two above, and the quality varies, and registration is often required before use. Recommend a foreign tool Online converter, a free online video conversion tool. You don't even need to install software, just select the corresponding target format, then upload the video, configure the parameters and you can convert it. If you don’t have the right tools, you can give it a try.

Step 2: Write the corresponding HTML5 video code

The video in HTML5 is actually a simple tag that contains some video-related information. I will directly give the specific code below, and then briefly explain it:

<video width="800" height="374">
    <source src="my_video.mp4" type="video/mp4" />
    <source src="my_video.ogv" type="video/ogg" />
    <source src="my_video.webm" type="video/webm" />
Copy after login

Your browser does not support the video function, click here to download the video:

The video tag indicates that this is a video, and the width and height attributes respectively indicate the width and height (in pixels) of the video content. The video tag can contain the source tag, which is used to indicate the referenced video and the format and type of the video. In order to ensure downward compatibility, we also added a prompt in the video tag. This sentence will not be displayed in browsers that support the video tag. If it is not supported, it will be displayed. Here, a video download address is also added. If the browser does not support it, users can choose to download it and watch it.

One thing to note in particular is that your host must be able to handle these video requests correctly. Make sure your host sends the correct MIME type in the Content-Type header when requested for these videos. If you are not sure, you can consult the hosting service provider or add it yourself. If the host supports .htaccess, you can add the following statement to the .htaccess file:

This is roughly it. It is relatively simple. For more specific methods of using video, you can search for it. You can also see the extended reading link of this article. I won’t go into details here.

Step 3: Make compatibility for old browsers

As mentioned before, if the browser does not support video, the prompt content in video will be displayed. So for old browsers, we can replace this prompt content with traditional flash. In this way, when the browser is not compatible with the video tag, the flash version of the video will be displayed. For example:

<video width="800" height="374">
<source src="my_video.mp4" type="video/mp4" />
<source src="my_video.ogv" type="video/ogg" />
<object width="800" height="374" type="application/x-shockwave-flash" data="fallback.swf">
<param name="movie" value="fallback.swf" />
<param name="flashvars" value="autostart=true&amp;file=video.flv" />
</object></video>
Copy after login

can be directly written into the video tag according to the original normal flash introduction method. In this way, we achieve cross-browser compatible use of the video function.

The above content is about the method of achieving browser compatibility for HTML5 video. I hope it can help everyone.

Related recommendations:

The issue of browser compatibility with HTML5 and CSS3

What are the browsers that require compatibility verification in HTML

Implement music playback js code compatible with various browsers

The above is the detailed content of HTML5 video method to achieve browser compatibility. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to remove Firefox Snap in Ubuntu Linux? How to remove Firefox Snap in Ubuntu Linux? Feb 21, 2024 pm 07:00 PM

To remove FirefoxSnap in Ubuntu Linux, you can follow these steps: Open a terminal and log in to your Ubuntu system as administrator. Run the following command to uninstall FirefoxSnap: sudosnapremovefirefox You will be prompted for your administrator password. Enter your password and press Enter to confirm. Wait for command execution to complete. Once completed, FirefoxSnap will be completely removed. Note that this will remove versions of Firefox installed via the Snap package manager. If you installed another version of Firefox through other means (such as the APT package manager), you will not be affected. Go through the above steps

How to fix VIDEO DXGKRNL fatal error in Windows 11 How to fix VIDEO DXGKRNL fatal error in Windows 11 Apr 13, 2023 pm 08:22 PM

Click to enter: ChatGPT Tool Plug-in Navigation Collection Some users complained that their computers frequently crashed with the stop code VIDEO DXGKRNL FATAL ERROR. This particular issue occurs only occasionally and has a bugcheck value of 0x00000113, which indicates a violation in the Microsoft DirectX graphics kernel subsystem, as indicated by the bugcheck value. Usually, the error occurs when a corrupt driver interferes with the normal operation of the graphics card's graphics processor. If you're currently struggling with this specific issue, our article will provide you with a variety of high-quality troubleshooting tips. Below you'll find various methods that other users who encountered the exact same error have used successfully. yes

Motorola Razr 50 Ultra shows up in leaked teaser video with waterproof case and huge secondary display Motorola Razr 50 Ultra shows up in leaked teaser video with waterproof case and huge secondary display Jun 20, 2024 pm 09:31 PM

Over the past few weeks, the most important specifications and the euro prices of the Motorola Razr 50 and the Razr 50 Ultra have been leaked. Now the enormously reliable leaker @MysteryLupin was able to publish the teaser video embedded below, which

Pixel 9 Pro XL vs iPhone 15 Pro Max camera comparison reveals surprising Google wins in video and zoom performance Pixel 9 Pro XL vs iPhone 15 Pro Max camera comparison reveals surprising Google wins in video and zoom performance Aug 24, 2024 pm 12:32 PM

The Google Pixel 9 Pro and Pro XL are Google's answers to the likes of the Samsung Galaxy S24 Ultra and the Apple iPhone 15 Pro and Pro Max. Daniel Sin on YouTube(watch below) has compared the Google Pixel 9 Pro XL to the iPhone 15 Pro Max with some

Can mozilla firefox be uninstalled? Can mozilla firefox be uninstalled? Mar 15, 2023 pm 04:40 PM

Mozilla Firefox can be uninstalled; Firefox is a third-party browser and can be uninstalled if it is not needed. Uninstallation method: 1. In the Start menu, click "Windwos System" - "Control Panel"; 2. In the "Control Panel" interface, click "Programs and Features"; 3. In the new interface, find and double-click Firefox Browser icon; 4. In the uninstall pop-up window, click "Next"; 5. Click "Uninstall".

Panasonic Lumix S9 supply shortages complete Fujifilm X100VI impersonation act despite bad press Panasonic Lumix S9 supply shortages complete Fujifilm X100VI impersonation act despite bad press Jun 14, 2024 am 09:36 AM

Sinceitslaunchearlierthisyear,thePanasonicLumixS9hasbeenembroiledincontroversy.BetweenthecornersPanasoniccuttoarriveatsuchasmallbodyandthefusscertaincamerareviewerskickeduponYouTube,itseemedliketheLumixS9wasdoom

A closer look at the video element in HTML A closer look at the video element in HTML Feb 24, 2024 pm 08:18 PM

Detailed explanation of the video tag in HTML The video tag in HTML5 is a tag used to play videos on web pages. It can render videos using different formats, such as MP4, WebM, Ogg, and more. In this article, we will introduce the use of video tag in detail and provide specific code examples. Basic Structure The following is the basic structure of the video tag:

Snapdragon X Elite CPU performance nearly identical on battery and plugged-in in Vivobook S15 benchmarks Snapdragon X Elite CPU performance nearly identical on battery and plugged-in in Vivobook S15 benchmarks Jun 20, 2024 pm 03:59 PM

Despite the hype surrounding the Qualcomm Snapdragon X Elite, it has been a rather mediocre launch. In our review, we found that the most impressive part of the new Qualcomm Snapdragon X Elite X1E-78-100-powered Asus Vivobook S 15 was the seamlessnes

See all articles