HTML videos (Videos)
There are many ways to play videos in HTML.
HTML video (Videos) playback
Instance
Run instance»
Click the "Run Example" button to view the online example
#Problems and Solutions
Playing videos in HTML is not easy!
You need to know a lot of techniques to ensure that your video files work in all browsers (Internet Explorer, Chrome, Firefox, Safari, Opera) and on all hardware (PC, Mac, iPad, iPhone) Play.
In this chapter, W3CSchool summarizes the problems and solutions for you.
Use the tag
The tag is used to embed multimedia elements in HTML pages.
The following HTML code displays a Flash video embedded in a web page:
Example
Run Example»
Click the "Run Instance" button to view the online instance
Problem
##HTML4 cannot recognize the tag. Your page cannot pass verification.
If the browser does not support Flash, the video will not playback
iPad and iPhone cannot display Flash videos.
If you convert the video to other formats, then it still won't play in all browsers.
##Use the
tag
The tag is used to embed multimedia elements in HTML pages.
The following HTML fragment shows a Flash video embedded in a web page:
Example
Problem:
If the browser does not support Flash, it will not work Play video.
iPad and iPhone cannot display Flash videos.
If you convert the video to other formats, then it still won't play in all browsers.
##Using the HTML5 element
HTML5 tag defines a video or movie.
The ; element is supported in all modern browsers.
The following HTML fragment displays a video in ogg, mp4 or webm format embedded in a web page:
Example
php中文网(php.cn)
您的浏览器不支持视频。
Run Instance»
Click the "Run Instance" button to view the online instance
Problem:
The best HTML solution
The following examples use 4 different video formats. The HTML 5 element attempts to play a video in one of the mp4, ogg, or webm formats. If both fail, fall back to the element.
Instance
Run Instance»
Click the "Run Instance" button to view the online instance
Problem:
Youku Solution Solution
The easiest way to display videos in HTML is to use a video website such as Youku.
If you want to play a video on a web page, you can upload the video to a video website such as Youku, and then insert the HTML code into your web page to play the video:
Using Hyperlinks
If a web page contains a hyperlink to a media file, most browsers will use a "helper application" to play the file .
The following code snippet displays a link to an AVI file. If the user clicks the link, the browser will launch a "helper application" such as Windows Media Player to play the AVI file:
Example
php中文网(php.cn)
点击这个链接打开查看 播放视频文件
Run Instance»
Click the "Run Instance" button to view the online instance
A note about inline videos
When a video is included in a web page, it is called an inline video.
If you plan to use inline video in a web application, you need to be aware that many people find inline video annoying.
Also note that users may have turned off the inline video option in their browser.
Our best advice is to only include inline videos in places where users expect to see them. A positive example is when a user needs to see a video and clicks on a link, which opens the page and then plays the video.
HTML Multimedia Tag
New : HTML5 new tag.