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:
- “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:
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
Please Login to comment...