Skip to content
Related Articles

Related Articles

HTML | DOM Video canPlayType( ) Method

View Discussion
Improve Article
Save Article
  • Last Updated : 13 Jul, 2022

The Video canPlayType() method is used for checking if the browser can play the specified video type or not. The Video canPlayType method returns a string which represents the level of support. 

Syntax:

videoObject.canPlayType(type)

Parameter Values:

  • type : It specifies the video type (and optional codecs) to test support for.

Return: The Video canPlayType() method generally returns one of the following values:

  • “probably” : It means that this video type is most likely supported for browser.
  • “maybe” :It means that the browser might support this video type.
  • “” (empty string) :It means that the browser does not support this video type.

Below program illustrates the Video canPlayType() method : 

Example: Checking if a browser can play different types of video or not. 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        DOM Video canPlayType( ) Method
    </title>
</head>
 
<body style="text-align: center">
 
    <h1 style="color: green">
      GeeksforGeeks
  </h1>
    <h2 style="font-family: Impact">
      Video canPlayType() Method
  </h2>
    <br>
 
    <p>
      Does the browser support playing OGG videos? <span>
<button ondblclick=
        "My_Video(event, 'video/ogg', 'theora, vorbis')"
        type="button">Check</button>
</span></p>
 
    <p>Does the browser support playing MP4 videos? <span>
<button ondblclick=
        "My_Video(event, 'video/mp4', 'avc1.42E01E, mp4a.40.2')"
         type="button">Check</button>
</span></p>
 
    <script>
        function My_Video(e, vidType, codType) {
 
            var v = document.createElement("Video");
            isSupp =
              v.canPlayType(vidType + ';codecs="'
                            + codType + '"');
           
            if (isSupp == "") {
                isSupp = "No";
            }
           
            e.target.parentNode.innerHTML =
              "Compatilibility : " + isSupp;
 
        }
    </script>
 
</body>
 
</html>


Output:

  • Before clicking the button:

 

  • After clicking the button: 

Supported Browsers: The browser supported by HTML | DOM Video canPlayType( ) Method are listed below:

  • Google Chrome 3 and above
  • Edge 12 and above
  • Internet Explorer 9 and above
  • Firefox 3.5 and above
  • Opera 12.1 and above
  • Apple Safari 4 and above

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!