Use js to check whether the browser supports the video tag in html5

Source: Internet
Author: User

Copy codeThe Code is as follows:
// Check whether HTML5 is supported
Function checkVideo (){
If (!! Document. createElement ('video'). canPlayType ){
Var vidTest = document. createElement ("video ");
OggTest = vidTest. canPlayType ('video/ogg; codecs = "theora, vorbis "');
If (! OggTest ){
Hsf-test = vidTest. canPlayType ('video/mp4; codecs = "avc1.42E01E, mp4a. 40.2 "');
If (! Hsf-test ){
Return false;
}
Else {
If (hsf-test = "probably "){
Return true;
}
Else {
Return false;
}
}
}
Else {
If (oggTest = "probably "){
Return true;
}
Else {
Return false;
}
}
}
Else {
Return false;
}
}

The above method can be used to determine whether the current browser supports the Video tag in HTML5 and supports playing in MP4 format (because Firefox does not support H. 264 encoded MP4 format). If true is returned, you can use the Video in HTML5 to play the Video. If false is returned, the Flash plug-in is used to play the Video.
This method is generally used for video websites, mobile phones, tablets, and other devices for video screen playback, mainly to be compatible with IOS;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.