Skip to main content
Skip table of contents

HLS stream playback with licence extension option example code

CONNECT-protected HLS playback with licence extension is implemented in the connect-post-delivery example code.

  1. As an alternative to the HLS stream playback example code, in this example code the Operator Vault (OpVault) is asynchronously downloaded from the licence server rather than kept in the application's resources. This is typically done once per licence server and is shown in the requestConnectOpVault() method. Playback is not attempted until an OpVault is successfully fetched by disabling the UI buttons controlling playback.

    JAVA
      private void requestConnectOpVault(String xOpVaultUri) {
        FileDownload.ResponseListener listener = new FileDownload.ResponseListener() {
          @Override
          public void onSuccess(byte[] xResponse) {
            // Keep the operator vault somewhere as a byte array.
            mOpVault = xResponse;
            // Can now continue with playback.
          }
    
          @Override
          public void onFailure(int xErrorCode, String xErrorMsg) {
            // Report the error, as playback with Connect is not possible without an operator vault.
          }
        };
        // Perform the asynchronous request.
        FileDownload opVaultDownload = new FileDownload(xOpVaultUri, listener);
        opVaultDownload.requestData();
      }
  2. In the HLS stream playback example code, you set up the OTVConnectMediaDrmCallback and pass its instance to the createInstance() method of OTVConnectManager. That part is not repeated here; in the connect-post-delivery example code, there are buttons to play two different streams requiring different callback instances. To switch between the streams, you must call:

    JAVA
    OTVConnectManager.releaseInstance();
  3. Licence extension is supported through the OTVConnectManager instance's methods. The OTVConnectManager provides the application with the expiry time (by notification or query) and another method for extending the licence. A dedicated listener, OTVLicenseExpirationListener, captures the licence expiry time of each decryption session (usually only one per stream playback).

    JAVA
    OTVLicenseExpirationListener licenseExpirationListener = (MediaDrm xMd, String xSessionId, long xExpirationTimeMs) -> {
      // License expiration time provided. Store the session ID (String) for later (required for extension of expiry queries).
      currentDrmSession = xSessionId;
      // Expiry time (long) is given in epoch time in milliseconds.
      licenceExpiryTimeMs = xExpirationTimeMs;
      // A value of 0 means no expiry time is set.
      if (xExpirationTimeMs > 0) {
        // Calculate time remaining, or do something else with this data.
      }
    };
    :
    :
    mConnectManager.setLicenseExpirationListener(licenseExpirationListener);

    The expiration notification onExpirationUpdate() is called when the licence is fetched or extended. The expiry time can also be queried:

    JAVA
     licenceExpiryTimeMs = mConnectManager.getLicenseExpirationTimeMs(currentDrmSession);
  4. The application needs to keep track of the licence's remaining time and decide if it wishes to extend the licence. In the example code provided, this is done through a background thread. When the application chooses to extend the licence, it may need to provide a new content token to the OTVConnectMediaDrmCallback instance, and then it needs to call the OTVConnectManager instance:

    JAVA
    // Fetch a new token (if required) and update the DRM callback.
    mConnectDrmCallback.setKeyRequestProperty("nv-authorizations", token);
    // New expiry time will be provided in the OTVLicenseExpirationListener listener method.
    mConnectManager.extendCurrentDrmLicense( currentDrmSession ); 
  5. Once the licence is extended, the application will be notified through the OTVLicenseExpirationListener instance of a new expiry time.

The licence extension and the consequent expiry notification do not happen immediately, but when the DRM session manager identifies that the existing (previous) licence is no longer valid.
Extending the CONNECT licence expiry time requires the CONNECT MediaDrm plugin version 3.2.0 or above. The details of the content token set extension of licence expiry. Setting expiry time can be done by either providing a duration value (in seconds) or by specifying an end time (UTC date).

  • When setting a floating duration, the extension occurs only after the current licence has expired, and the app will not be notified with a meaningful expiry time in the onExpirationUpdate event.

  • When setting an end time, the extension occurs immediately, and the app will be notified within the onExpirationUpdate event with time (in ms) since the Unix epoch.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.