To test this feature and view the example code, please see the (5.33.x) Android SDK 5 Example Code Quick Start guide.
CONNECT-protected DASH playback is implemented in the connect-dash example code as follows.
-
In Android Studio, add the OpVault to the application build project as a project resource.
The usual SDK initialisation precedes any other SDK access. InMainActivity:JavaOTVSDK.load(this); -
An
OTVConnectMediaDrmCallbackmust be instantiated to be passed to the player:Java// Adjust string below to match your licence server String CONNECT_LICENSE_SERVER = "https://licenseserverurl.com/TENANT_ID/prmls/contentlicenseservice/v1/licenses/"; OTVConnectMediaDrmCallback connectDrmCallback = new OTVConnectMediaDrmCallback(CONNECT_LICENSE_SERVER); -
An instance of
OTVConnectMediaDrmCallbackneeds to be created with the following configuration (which translate to HTTP request header properties:JavaconnectDrmCallback.setKeyRequestProperty("Accept", "application/json"); connectDrmCallback.setKeyRequestProperty("Content-Type", "application/json"); // Replace the value with the real data. connectDrmCallback.setKeyRequestProperty("nv-tenant-id", "--tenant_id--"); -
The OpVault must be read from its file, so the following method is provided.
Javaprivate byte[] loadOpVault() { // Loading connect_opvault in src/main/res/raw try { byte[] buffer = new byte[1024 * 4]; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); int bytesRead; InputStream opvaultStream = getResources().openRawResource(R.raw.connect_opvault); while ((bytesRead = opvaultStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } return outputStream.toByteArray(); } catch (IOException e) { OTVLog.e(TAG, e.getMessage()); finish(); } return new byte[0]; } -
The OpVault data is read as a byte array and passed to the callback as a
"nagraOpVault"DRM property:Javabyte[] opVault = loadOpVault(); connectDrmCallback.setDrmPropertyByteArray("nagraOpVault", opVault); -
An OTVVideoViewobject must be instantiated and attached to a UI frame.JavasetContentView(R.layout.activity_main); FrameLayout frame = findViewById(R.id.frame); OTVVideoView otvVideoView = new OTVVideoView(this); frame.addView(otvVideoView);For improved functionality, you can add listeners here for player events coming from the
OTVVideoViewinstance (see the example code). -
Before starting playback, the
OTVConnectMediaDrmCallbackinstance must be configured with the stream's encryption properties; for example:Java// Replace the values with the real data. connectDrmCallback.setKeyRequestProperty("nv-authorizations", "--stream_token--"); // Set application data if necessary connectDrmCallback.setKeyRequestOption("clientData", "thisIsClientData"); -
Provide a method for starting playback on the UI thread. In this example, it will be called immediately.
Javaprivate static final String STREAM_URI = "https://cdnurl.com/mystream.m3u8"; private void startPlayback() { runOnUiThread(() -> { otvVideoView.setVideoPath(STREAM_URI); otvVideoView.start(); }); } -
Provide the player with the
connectDrmCallbackthat has been created and configured, and playback can start.JavaotvVVideoView.setMediaDrmCallback(connectDrmCallback); startPlayback();