EME Extension - Policy Check Sample

Available in Chrome 69+ | View on GitHub | Browse Samples

Background

The EME Extension, Policy Check API allows web developers to query the status of a hypothetical key associated with an HDCP policy, without the need to create a MediaKeySession or fetch a real license. It does not require the MediaKeys to be attached to any HTMLMediaElement either. If HDCP is available at the specified version, the promise should return a MediaKeyStatus of "usable".

Note: In Chrome 69, it is available for trials so that websites can use it without any experimental flag.

Live Output


JavaScript Snippet

function onButtonClick() {
  const minHdcpVersion = document.querySelector('#minHdcpVersion').value;
  const config = [{
    videoCapabilities: [{
      contentType: 'video/webm; codecs="vp09.00.10.08"',
      robustness: 'SW_SECURE_DECODE' // Widevine L3
    }]
  }];
  
  log('Requesting Widevine system access...');
  navigator.requestMediaKeySystemAccess('com.widevine.alpha', config)
  .then(mediaKeySystemAccess => mediaKeySystemAccess.createMediaKeys())
  .then(mediaKeys => {
    log('Getting HDCP status...');
    if (!('getStatusForPolicy' in mediaKeys)) {
      return Promise.reject('HDCP Policy Check API is not available.');
    }

    /* This is where the real magic happens... */
    return mediaKeys.getStatusForPolicy({ minHdcpVersion });
  })
  .then(status => {
    if (status !== 'usable') {
      return Promise.reject(status);
    }

    log('> HDCP is available for ' + minHdcpVersion);
  })
  .catch(error => {
    log('Argh! ' + error);
  });
}