canPlayType背后的理由是什么?

时间:2015-07-24 14:25:09

标签: javascript html5 html5-video html5-audio

所以,我最近在Twitter上看到了对canPlayType的引用。基本上总结是:

The canPlayType() method checks if the browser can play the specified audio/video type.

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

"probably" - the browser most likely supports this audio/video type
"maybe" - the browser might support this audio/video type
"" - (empty string) the browser does not support this audio/video type

为什么它不像典型的API那样只返回true / false?...为什么非常模糊的术语“可能”和“可能”?

1 个答案:

答案 0 :(得分:1)

为什么呢?因为这是规范所说的http://dev.w3.org/html5/spec-preview/media-elements.html#dom-navigator-canplaytype

  

如果type是用户代理知道它无法呈现的类型或类型为“application / octet-stream”,则{{1}}方法必须返回空字符串;如果用户代理确信该类型表示如果与此音频或视频元素一起使用它可以呈现的媒体资源,则它必须返回“可能”;并且它必须返回“可能”否则。鼓励实施者返回“可能”,除非该类型可以自信地建立为支持与否。通常,如果不存在该参数,则用户代理永远不应返回允许编解码器参数的类型的“可能”。

相关问题