canPlayType method
Returns a string that specifies whether the client can play a given media resource type.
Syntax
retVal = object.canPlayType(type, canPlay);
Parameters
type [in]
Type: string
The mime type of media that the client is being asked to play.
canPlay [out, retval]
Type: string
probably
The type of media that is most likely to be rendered.
maybe
The type of media that might be able to be rendered
[empty string]
The media type cannot be rendered, or the media engine isn't available.
Return value
This method does not return a value.
Standards information
- HTML5 A vocabulary and associated APIs for HTML and XHTML, Section 4.8.9.2
Remarks
Positive return values are slightly vague because of the implementation variations in video and audio formats.
Examples
This code segment is from the demo featured in How to use HTML5 to play video files on your webpage and shows how to use canPlayType. Try the example online.
if (myvideo.canPlayType) {
// CanPlayType returns maybe, probably, or an empty string.
var playMsg = myvideo.canPlayType('video/mp4; codecs="avc1.42E01E"');
if ("" != playMsg) {
msg.innerHTML += "mp4/H.264 is " + playMsg + " supported <br/>";
}
playMsg = myvideo.canPlayType('video/ogg; codecs="theora"');
if ("" != playMsg) {
msg.innerHTML += "ogg is " + playMsg + " supported<br/>";
}
playMsg = myvideo.canPlayType('video/webm; codecs="vp8, vorbis"');
if ("" != playMsg) {
msg.innerHTML += "webm is " + playMsg + " supported<br/>";
}
}
else {
msg.innerHTML += "no video support";
}
}