大网数据广告活动
Web 标准与前端开发

Navigator: requestMediaKeySystemAccess() method

· 52CE 我爱测

The **`requestMediaKeySystemAccess()`** method of the Navigator interface returns a 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.

Encrypted Media Extensions

The requestMediaKeySystemAccess() method of the Navigator interface returns a 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 object's MediaKeySystemAccess.createMediaKeys method.

Syntax

requestMediaKeySystemAccess(keySystem, supportedConfigurations)

Parameters

  • keySystem
    • : A string identifying the key system. For example com.example.some-system or org.w3.clearkey.
  • supportedConfigurations
    • : A non-empty Array of objects conforming to the object returned by MediaKeySystemAccess.getConfiguration. The first element with a satisfiable configuration will be used.

      Each object may have the following properties:

      [!NOTE] Either videoCapabilities or audioCapabilities may be empty, but not both!

      • label

        • : An optional label for the configuration, which defaults to "". This label is preserved for configurations fetched using MediaKeySystemAccess.getConfiguration
      • initDataTypes

      • audioCapabilities

        • : An array of supported audio capabilities. If the array is empty the content type does not support audio capabilities.

          Each object in the array has the following properties:

          • contentType
            • : A string indicating the media MIME-type of the media resource, such as "audio/mp4;codecs=\"mp4a.40.2\". Note that the empty string is invalid, and that if the MIME-type definition includes parameters, such as codecs, these must also be included.
          • encryptionScheme
            • : The encryption scheme associated with the content type, such as cenc, cbcs, cbcs-1-9. This value should be set by an application (it defaults to null, indicating that any encryption scheme may be used).
          • robustness
            • : The robustness level associated with the content type. The empty string indicates that any ability to decrypt and decode the content type is acceptable.
      • videoCapabilities

        • : An array of supported video capabilities. The objects in the array have the same form as those in audioCapabilities.
      • distinctiveIdentifier

        • : A string indicating whether the implementation may use "distinctive identifiers" (or distinctive permanent identifiers) for any operations associated with any object created from this configuration. The allowed values are:
          • required
            • : The returned object must support this feature.
          • optional
            • : The returned object may support this feature. This is the default
          • not-allowed
            • : The returned object must not support or use this feature.
      • persistentState

        • : A string indicating whether the returned object must be able to persist session data or any other type of state. The values are the same as for distinctiveIdentifier and have the same meaning: required, optional (default), not-allowed. Only "temporary" sessions may be created when persistent state is not allowed.
      • sessionTypes

        • : An array of strings indicating the session types that must be supported. Permitted values include:
          • temporary
            • : A session for which the license, key(s) and record of or data related to the session are not persisted. The application does not need to manage such storage. Implementations must support this option, and it is the default.
          • persistent-license
            • : A session for which the license (and potentially other data related to the session) will be persisted. A record of the license and associated keys persists even if the license is destroyed, providing an attestation that the license and key(s) it contains are no longer usable by the client.

Return value

A Promise that fulfills with a MediaKeySystemAccess object representing the media key system configuration described by keySystem and supportedConfigurations.

Exceptions

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

  • NotSupportedError DOMException
    • : 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).
  • SecurityError DOMException
  • TypeError
    • : Either keySystem is an empty string or the supportedConfigurations array is empty.

Examples

The example below shows how you might use requestMediaKeySystemAccess(), specifying a key system and configuration.

const 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((keySystemAccess) => {
    /* use the access to get create keys */
  });

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。