canPlayType method

Returns a string that specifies whether the client can play a given media resource type.

HTML5 A vocabulary and associated APIs for HTML and XHTML, Section 4.8.9.2Internet Explorer 9

Syntax

object.canPlayType(type, canPlay)

Parameters

type [in]

Type: String

The mime type of media that the client is being asked to play.

Return value

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.

Standards information

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.


            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";
            }
        }


See also

audio element
audio object
media element
video element
video object
How to use HTML5 to play video files on your webpage
How to use HTML5 to Add an Audio Player to your Webpage

 

 

Show:
© 2014 Microsoft. All rights reserved.