Skip to content
Related Articles

Related Articles

Improve Article

HTML | DOM Audio canPlayType() Method

  • Last Updated : 14 Apr, 2021

The Audio canPlayType() method is used for checking if the browser can play the specified audio type or not.
Return: The Audio canPlayType() method generally returns one of the following values: 
 

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

Syntax 
 

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

audioObject.canPlayType(type)

Example: 
 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        DOM Audio canPlayType( ) Method
    </title>
</head>
 
<body style="text-align: center">
 
    <h1 style="color: green">
    GeeksforGeeks
</h1>
    <h2 style="font-family: Impact">
    Audio canPlayType() Method
</h2>
    <br>
 
     
<p>
        Does the browser support playing OGG audios? <span>
<button ondblclick=
        "My_Audio(event, 'audio/ogg', 'vorbis')"
        type="button">Check</button>
</span></p>
 
 
     
<p>Does the browser support playing OGG audios? <span>
<button ondblclick=
        "My_Audio(event, 'audio/ogg', 'vorbis')"
        type="button">Check</button>
</span></p>
 
 
    <script>
        function My_Audio(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: 
 



After: 
 

Supported Browsers: 
 

  • Chrome
  • Mozilla Firefox
  • Internet Explorer 9.0
  • Opera
  • Safari

 




My Personal Notes arrow_drop_up
Recommended Articles
Page :