Audio/Video

Audio/Video 方法

addTextTrack() canPlayType() load() play() pause()

Audio/Video 属性

audioTracks autoplay buffered controller controls crossOrigin currentSrc currentTime defaultMuted defaultPlaybackRate duration ended error loop mediaGroup muted networkState paused playbackRate played readyState readyState seekable seeking src startDate textTracks videoTracks volume

Audio/Video 事件

onabort oncanplay oncanplaythrouth ondurationchange emptied onended onerror onloadeddata onloadedmetadata onloadstart onpause onplay onplaying onprogress onratechange onseeked onseeking onstalled onsuspend ontimeupdate onvolumechange onwaiting

JavaScript对象

基础内容

基础

HTML DOM

DOM Document DOM Elements DOM Attributes DOM Events

浏览器BOM

Window Navigator Screen History Location

html对象

a abbr address area article aside audio b base bdo blockquote body br button canvas caption cite code col colgroup datalist dd del details dfn dialog div dl dt em embed fieldset figcaption figure footer form h1~h6 head hr html i iframe img input button input checkbox input color input date input datetime input datetime-local input email input file input hidden input image input month input number input password input radio input range input reset input search input submit input text input time input url input week ins kbd keygen label legend li link map mark menu meta meter nav object ol optgroup option output p param pre progress q s samp script scetion select small source span strong style

canPlayType();检查浏览器是否能够播放指定的视频、声频

使用canPlayType()方法检查浏览器是否能够播放指定的视频、声频。canPlayType()方法能够返回以下值:

  • "probably" : 浏览器最有可能支持视频的类型
  • "maybe" : 浏览器或许能够支持视频的类型
  • " " : 空字符,浏览器不支持视频的类型
参数值及其说明
说明
type 指定视频的种类以及解码器,常用值如下:
  • video/mp4
  • video/ogg
  • video/webm

同时指定常用值及解码器:
  • video/ogg; codecs="theora,vorbis"
  • video/mp4;codecs="avc1.4D401E,mp4a.40.2"
  • video/webm;codecs="vp8.0,vorbis"
注:如果带有解码器,将仅返回“probably”。
JavaScript 语法:audio/video.canPlayType(kind,label,language);

使用例

浏览器支持MP4型视频吗?

浏览器支持OGG型视频吗?

<!DOCTYPE html>

<html>

<body>

<p>浏览器支持MP4型视频吗? <span>

<button onclick="supportType(event,'video/mp4')" type="button">点击测试</button>

</span></p>

<p>浏览器支持OGG型视频吗? <span>

<button onclick="supportType(event,'video/ogg')" type="button">点击测试</button>

</span></p>

<script>

function supportType(e,vidType) {

var x = document.createElement("VIDEO");

isSup = x.canPlayType(vidType);

if (isSup == "") {

isSup = "No";

}

e.target.parentNode.innerHTML = "答案: " + isSup;

}

</script>

</body>

</html>

不同浏览器的对应情况

元素
canPlayType() 9.0 yes yes yes yes