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 Video 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



audioObject.canPlayType(type)

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:
Before:

After:

Supported Browsers:

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


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.