Home  >  Article  >  Web Front-end  >  The method canPlayType() in HTML5 determines whether the browser can play the specified audio/video type.

The method canPlayType() in HTML5 determines whether the browser can play the specified audio/video type.

黄舟
黄舟Original
2017-11-07 11:21:242489browse

Example

Detect whether your browser can play different types of videos:

myVid=document.createElement('video');
isSupp=myVid.canPlayType(vidType+';codecs="'+codType+'"');

Definition and usage

canPlayType() method browsing Whether the device can play the specified audio/video type.

The canPlayType() method can return one of the following values:

  • "probably" - The browser is most likely to support this audio/video type

  • "maybe" - The browser may support this audio/video type

  • "" - (empty string) The browser does not support this audio /Video Type

Browser support

All browsers support the canPlayType() method.

Note: This method is not supported in Internet Explorer 8 and earlier.

Syntax

audio|video.canPlayType(type))

Parameters

Return value
Value Description
type

specifies the audio/video type to be detected.

Common values:

  • video/ogg

  • ##video/mp4

  • video/webm

  • audio/mpeg

  • audio/ogg

  • ##audio/mp4
  • Common values, including codecs:

    video/ogg; codecs="theora, vorbis"
  • video/mp4; codecs="avc1.4D401E, mp4a.40.2"
  • video/webm; codecs="vp8.0, vorbis"
  • audio/ogg; codecs="vorbis"
  • ##audio/mp4; codecs="mp4a.40.5"
  • Note: Only "probably" can be returned if the codec is included.

TypeDescriptionString
indicates the supported level. Possible values:

"probably" - most likely supported
  • "maybe" - probably supported
  • "" - (empty string)
is not supported

The above is the detailed content of The method canPlayType() in HTML5 determines whether the browser can play the specified audio/video type.. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn