How to download ClearKey Encrypted Video in ExoPlayer 2

1.1k Views Asked by At

I am having a .MPD file which is encrypted via ClearKey DRM scheme. I am able to play this file in Exoplayer2 with internet connectivity. Exoplayer2 is using LocalMediaDrmCallback for licensing the .MPD file

Now, i am trying to download this video offline, after that playing that offline video in Exoplayer2(without internet connectivity).

Till now i have tried to use DashDownloadHelper to download the video from .MPD file. Please guide me how to provide licensing information while downloading the file.

1

There are 1 best solutions below

0
On BEST ANSWER

You can simply download the content like normal .MPD file and do the licensing in two ways i.e.

  • online while playing the video using HttpMediaDrmCallback
 HttpDataSource.Factory licenseDataSourceFactory = CinemaApplication.getAppInstance().buildHttpDataSourceFactory();
            HttpMediaDrmCallback httpMediaDrmCallback =
                    new HttpMediaDrmCallback(licenseUrl, licenseDataSourceFactory);
            if (keyRequestPropertiesArray != null) {
                for (int i = 0; i < keyRequestPropertiesArray.length - 1; i += 2) {
                    httpMediaDrmCallback.setKeyRequestProperty(keyRequestPropertiesArray[i],
                            keyRequestPropertiesArray[i + 1]);
                }
            }
  • By using LocalMediaDrmCallback

    drmCallback = new LocalMediaDrmCallback(PlayerActivity.KEY_JSON.getBytes());

Using the above drmCallback, make te instance of DefaultDrmSessionManager

releaseMediaDrm();
mediaDrm = FrameworkMediaDrm.newInstance(uuid);
DefaultDrmSessionManager<FrameworkMediaCrypto> drmSessionManager = new DefaultDrmSessionManager<>(uuid, mediaDrm, drmCallback, null, false);

For more reference for offline ClearKey License