HTMLMediaElement.canPlayType()
HTMLMediaElement.canPlayType()
方法会判断传递的媒体格式参数是否能够被播放。
Note: This feature is not available in Web Workers.
语法
str = audioOrVideo.canPlayType(mediaType);
参数
- mediaType
DOMString
包含了媒体文件的MIME类型。
返回值
String
. 有可能的值为:
'probably'
: 这种媒体文件似乎是可播放的。'maybe'
: 不能告诉你这种媒体文件是否能被播放,直到你尝试播放它。''
(empty string): 这种媒体文件不能被播放。
提醒: 以前 canPlayType('video/webm')
会返回 'probably'。
从 Gecko 28 (Firefox 28 / Thunderbird 28 / SeaMonkey 2.25 / Firefox OS 1.3) 开始, 将返回 'maybe'
。 (bug 884275)
示例
var obj = document.createElement('video');
console.log(obj.canPlayType('video/mp4')); // "maybe"
规范
Specification | Status | Comment |
---|---|---|
HTML Living Standard HTMLMediaElement.canplaytype |
Living Standard | 从 HTML5后没有变更 |
HTML5 HTMLMediaElement.canplaytype |
Recommendation | 初始定义. |
浏览器兼容性
BCD tables only load in the browser
其他
- 接口定义,
HTMLMediaElement
.