Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. MediaKeys

MediaKeys

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨March 2019⁩.

* Some parts of this feature may have varying levels of support.

Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.

TheMediaKeys interface ofEncrypted Media Extensions API represents a set of keys that an associatedHTMLMediaElement can use for decryption of media data during playback.

Instance properties

None.

Instance methods

MediaKeys.createSession()

Returns a newMediaKeySession object, which represents a context for message exchange with a content decryption module (CDM).

MediaKeys.getStatusForPolicy()

Returns aPromise that resolves to a status string indicating whether the CDM would allow the presentation of encrypted media data using the keys, based on specified policy requirements.

MediaKeys.setServerCertificate()

Returns aPromise to a server certificate to be used to encrypt messages to the license server.

Examples

Check if keys are usable with HDCP restriction

This example shows howgetStatusForPolicy() can be used to check if keys can decrypt a particular video format in a setup that has a minimum HDCP version of2.2.For more information, see theMediaKeys: getStatusForPolicy() method documentation.

HTML

html
<pre></pre>
#log {  height: 100px;  overflow: scroll;  padding: 0.5rem;  border: 1px solid black;}

JavaScript

const logElement = document.querySelector("#log");function log(text) {  logElement.innerText = `${logElement.innerText}${text}\n`;  logElement.scrollTop = logElement.scrollHeight;}
js
const config = [  {    videoCapabilities: [      {        contentType: 'video/mp4; codecs="avc1.640028"',        encryptionScheme: "cenc",        robustness: "SW_SECURE_DECODE", // Widevine L3      },    ],  },];getMediaStatus(config);async function getMediaStatus(config) {  try {    const mediaKeySystemAccess = await navigator.requestMediaKeySystemAccess(      "com.widevine.alpha",      config,    );    const mediaKeys = await mediaKeySystemAccess.createMediaKeys();    const mediaStatus = await mediaKeys.getStatusForPolicy({      minHdcpVersion: "2.2",    });    log(mediaStatus);    // Get the content or fallback to an alternative if the    // keys are not usable    if (mediaStatus === "usable") {      console.log("HDCP 2.2 can be enforced.");      // Fetch the high resolution protected content    } else {      log("HDCP 2.2 cannot be enforced");      // Fallback other content, get license, etc.    }  } catch (error) {    log(error);  }}

Results

Specifications

Specification
Encrypted Media Extensions
# mediakeys-interface

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp