Skip to main content
Skip table of contents

Unified API playback of encrypted content

To test this feature and view the example code, please see the Unified API Example Code Quick Start guide.

The implementation of Encrypted content for UPI is mainly handled through a class called OTVUPISource, below are the method for importing, implementing and receiving information from the class:

Import classes

To play encrypted DASH content using UPI, the application first needs to import the following.

JAVA
import nagra.otv.upi.OTVUPISource;
import nagra.otv.upi.IOTVUPIPlayer;
import nagra.otv.upi.OTVUPIEventListener;
import nagra.otv.upi.OTVUPIPlayerFactory;

Implementing OTVUPISource  and IOTVUPIPlayer

Once the packages are imported, you will need to create an OTVUPISource Object to hold your DRM values, such as source url token and type. To create the UPI Player, the application has to invoke the method createPlayer(Context context, OTVUPISource source) from the OTVUPIPlayerFactory. Both of these should typically be set during an activity's OnCreate(). An example of this being implemented is shown below.

JAVA
  private final String ENCRYPTED_STREAM_URI = "https:streamurl.com/videofile.mpd";
  private final String STREAM_TOKEN = "JDb250ZW50QXV0aFoiLCJjb250ZW50UmlnaHRzIjpbeyJkd.Adw8dafW9aouiJFkxP203.eyJ2ZXIiOiIxLjAiLCJ0eXA";
  private final String DRM_URI = "https://drmurl.com/path/to/licenses";
  private final String CERTIFICATE_URL = "";
  private final String SSM_SERVER_URL = "";
  private final String DRM_TPYE = "widevine";
  private final Boolean SSM_SYNC_MODE = "false";

...

OTVUPISource mOTVUPISource = new OTVUPISource();
mOTVUPISource.setSrc(ENCRYPTED_STREAM_URI);
mOTVUPISource.setDrm(new OTVUPISource.Drm(DRM_TYPE, CERTIFICATE_URL, DRM_URI, SSM_SERVER_URL, SSM_SYNC_MODE));
mOTVUPISource.setToken(STREAM_TOKEN);
mOTVUPISource.setType("application/dash+xml");

All the above values are representative of a typical DRM license request.

Note that the stream (content) token may not be known at time of setting the source (may be fetched from the head-end concurrently). In such cases, the application may call mOTVUPISource.setToken() once it is retrieved, even after the IOTVUPIPlayer instance was created (as long as the reference to mOTVUPISource is kept).

The OTVUPISource class allows the application to set or get the source properties, the list of properties that you can set or get from an instantiated object is as follows:

  • Src (String address of the video)

  • Type(String representation of the MIME-type)

  • Token(String value of the SSP stream token used for DRM encryption)

  • AdTagUrl(String address of the Advert tag URL)

  • TextTracks(TextTrack[] sideloaded tracks for subtitles)

  • Drm(Drm object typically containing the type, DRM URI and sync mode settings)

OTVUPISource can be initialized empty and have its values set as shown above or upon the construction of the OTVUPISource as shown below:

JAVA
  private final String ENCRYPTED_STREAM_URI = "https:streamurl.com/videofile.mpd";
  private final String STREAM_TOKEN = "JDb250ZW50QXV0aFoiLCJjb250ZW50UmlnaHRzIjpbeyJkd.Adw8dafW9aouiJFkxP203.eyJ2ZXIiOiIxLjAiLCJ0eXA";
  private final String DRM_URI = "https://drmurl.com/path/to/licenses";
  private final String CERTIFICATE_URL = "";
  private final String SSM_SERVER_URL = "";
  private final String DRM_TPYE = "widevine";
  private final String AD_TAG_URL = "";
  private final TextTrack[] TEXT_TRACKS = null;
  private final Boolean SSM_SYNC_MODE = "false";

  ...


  OTVUPISource.Drm mDrm = new OTVUPISource.Drm(DRM_TYPE, CERTIFICATE_URL, DRM_URI, SSM_SERVER_URL, SSM_SYNC_MODE);
  OTVUPISource mOTVUPISource = new OTVUPISource(ENCRYPTED_STREAM_URI, DRM_TYPE, STREAM_TOKEN, AD_TAG_URL, TEXT_TRACKS, mDrm);

When creating an OTVUPISource this way, only the text tracks and DRM may be null values; the ad tag must at least contain an empty string.

Preparing the listener

To prepare the listener, see the instructions under Unified API playback of clear content.

Setting the view

To set the view, see Unified API playback of clear content.

JAVA
  private FrameLayout mFrame = null;
  private IOTVUPIPlayer mIOTVUPIPlayer ;

  static private class MyUPIEventListener extends OTVUPIEventListener {
	//add events here if needed
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    mFrame = findViewById(R.id.frame);

	...

    mIOTVUPIPlayer = OTVUPIPlayerFactory.createPlayer(context, mOTVUPISource, new MyUPIEventListener());
    if (mIOTVUPIPlayer != null) {
      mIOTVUPIPlayer.setView(mFrame);
    }
  }
JavaScript errors detected

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

If this problem persists, please contact our support.