簡體   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