Open In App

HTML | DOM Audio canPlayType() Method

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: 
 

Syntax 
 



audioObject.canPlayType(type)

Example: 
 




<!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: 
 

 


Article Tags :