Navigator.requestMediaKeySystemAccess() 方法返回 Promise which delivers a MediaKeySystemAccess object that can be used to access a particular media key system, which can in turn be used to create keys for decrypting a media stream. This method is part of the Encrypted Media Extensions API , which brings support for encrypted media and DRM-protected video to the web.

This method may have user-visible effects such as asking for permission to access one or more system resources. Consider that when deciding when to call requestMediaKeySystemAccess () ; you don't want those requests to happen at inconvenient times. As a general rule, this function should be called only when it's about time to create and use a MediaKeys object by calling the returned MediaKeySystemAccess 对象的 createMediaKeys() 方法。

句法

Promise = Navigator.requestMediaKeySystemAccess(keySystem, supportedConfigurations);
					

参数

keySystem
DOMString identifying the key system. For example com.example.somesystem or org.w3.clearkey .
supportedConfigurations
A non-empty 数组 of MediaKeySystemConfiguration objects. The first element with a satisfiable configuration will be used.

返回值

A Promise that, when resolved, delivers a MediaKeySystemAccess object to your fulfillment handler function. The fulfillment handler receives as input just one parameter:

mediaKeySystemAccess
MediaKeySystemAccess object representing the media key system configuration described by keySystem and supportedConfigurations

异常

In case of an error, the returned Promise is rejected with a DOMException whose name indicates what kind of error occurred.

NotSupportedError
Either the specified keySystem isn't supported by the platform or the browser, or none of the configurations specified by supportedConfigurations can be satisfied (if, for example, none of the codecs specified in contentType are available).
TypeError
要么 keySystem is an empty string or the supportedConfigurations array is empty.

规范

规范 状态 注释
加密媒体扩展
The definition of 'requestMediaKeySystemAccess()' in that specification.
推荐 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
requestMediaKeySystemAccess Chrome 42
42
The spec requires that the passed supportedConfigurations option contain at least one of audioCapabilities or videoCapabilities , and that said parameters include a codec string.
The function does not exist in insecure contexts. This was not enforced until Chrome 58.
Edge 13 Firefox Yes
Yes
Starting in Firefox 55, if neither audioCapabilities nor videoCapabilities 指定在 supportedConfigurations , a warning is output to the web console.
In addition, starting in Firefox 55, if in supportedConfigurations , either audioCapabilities 's or videoCapabilities 's contentType value doesn't specify a "codecs" substring to define allowed codecs within the media wrapper, a warning is output to the web console. See note below table for example and correction.
In the future, if neither audioCapabilities nor videoCapabilities is specified in the supportedConfigurations NotSupported exception will be thrown.
IE ? Opera 29
29
The spec requires that the passed supportedConfigurations option contain at least one of audioCapabilities or videoCapabilities , and that said parameters include a codec string.
The function does not exist in insecure contexts. This was not enforced until Opera 45.
Safari ? WebView Android 43
43
The spec requires that the passed supportedConfigurations option contain at least one of audioCapabilities or videoCapabilities , and that said parameters include a codec string.
The function does not exist in insecure contexts. This was not enforced until version 58.
Chrome Android 42
42
The spec requires that the passed supportedConfigurations option contain at least one of audioCapabilities or videoCapabilities , and that said parameters include a codec string.
The function does not exist in insecure contexts. This was not enforced until Chrome 58.
Firefox Android Yes
Yes
Starting in Firefox 55, if neither audioCapabilities nor videoCapabilities 指定在 supportedConfigurations , a warning is output to the web console.
In addition, starting in Firefox 55, if in supportedConfigurations , either audioCapabilities 's or videoCapabilities 's contentType value doesn't specify a "codecs" substring to define allowed codecs within the media wrapper, a warning is output to the web console. See note below table for example and correction.
In the future, if neither audioCapabilities nor videoCapabilities is specified in the supportedConfigurations NotSupported exception will be thrown.
Opera Android 29
29
The spec requires that the passed supportedConfigurations option contain at least one of audioCapabilities or videoCapabilities , and that said parameters include a codec string.
The function does not exist in insecure contexts. This was not enforced until Opera 45.
Safari iOS ? Samsung Internet Android 4.0
4.0
The spec requires that the passed supportedConfigurations option contain at least one of audioCapabilities or videoCapabilities , and that said parameters include a codec string.
The function does not exist in insecure contexts. This was not enforced until Samsung Internet 7.0.

图例

完整支持

完整支持

兼容性未知 ?

兼容性未知

见实现注意事项。

Firefox compatibility notes

Firefox 55 outputs a warning to the console if a candidate MediaKeySystemConfiguration included in supportedConfigurations includes an audioCapabilities or videoCapabilities object whose value of contentType doesn't specify a "codecs" substring defining which codecs within the media wrapper format should be allowed.

例如:

let clearKeyOptions = [
  {
    initDataTypes: ['keyids', 'webm'],
    audioCapabilities: [
      { contentType: 'audio/webm' }
    ],
    videoCapabilities: [
      { contentType: 'video/webm' }
    ]
  }
];
navigator.requestMediaKeySystemAccess('org.w3.clearkey', clearKeyOptions)
.then(function(keySystemAccess) {
  /* use the access to get create keys */
});
													

The code above works in Firefox up to version 55, but version 55 onwards will output a warning to console, because "codecs" is not included in the contentType strings. This could be corrected as follows:

let clearKeyOptions = [
  {
    initDataTypes: ['keyids', 'webm'],
    audioCapabilities: [
      { contentType: 'audio/webm; codecs="opus"' },
      { contentType: 'audio/webm; codecs="vorbis"' }
    ],
    videoCapabilities: [
      { contentType: 'video/webm; codecs="vp9"' },
      { contentType: 'video/webm; codecs="vp8"' }
    ]
  }
];
navigator.requestMediaKeySystemAccess('org.w3.clearkey', clearKeyOptions)
.then(function(keySystemAccess) {
  /* use the access to get create keys */
});
													

In this revised example, the audio and video capabilities include possible codecs which should be permitted, and therefore are valid requests.

另请参阅

元数据

  • 最后修改: