繁体   English   中英

canPlayType背后的原理是什么?

[英]What is the rationale behind canPlayType?

因此,我最近在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?...以及为什么非常模糊的术语“也许”和“可能”?

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

如果type是用户代理知道无法呈现的类型,或者类型是“ application / octet-stream”,则canPlayType(type)方法必须返回空字符串; 如果用户代理确信类型代表与该音频或视频元素一起使用时可以呈现的媒体资源,则它必须返回“可能”; 并且必须返回“也许”。 鼓励实现者返回“也许”,除非可以肯定地将其确定为受支持的类型。 通常,对于允许编解码器参数的类型,如果该参数不存在,则用户代理绝对不应返回“可能”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM