Play Multi-key DRM contents on ExoPlayer (part-2)

Image for post
Image for post

In the previous article, I wrote about what is Multi-key and how to create sample multi-key contents. In this article, I will explain how to play them. If you have not read the previous article, I would recommend to read this first.

MediaDrmCallback

In ExoPlayer, MediaDrmCallback.java is responsible for requesting keys, and you can just return a key response immediately without requesting to the license server. (of course, preparing your own license server works too.)

In this Article, I will not build a license server for simplicity.

Key Response Pattern

If you have multiple keys (like video/audio or HD/FHD), there could be two possible patterns. Note that the kids and keys in requests and responses are all base64url encoded.

Case 1: License server responds with all keys for the content

// request
{
"kids":[
"x3_uNeUf1hWnuRr8sQkcXg" // video kid
],
"type":"temporary"
}
// response
{
"keys":[
{
"kty":"oct",
"k":"7s2ytUnwKnyXzlDBf0lMoA",
"kid":"x3_uNeUf1hWnuRr8sQkcXg"
},
{
"kty":"oct",
"k":"mrt6tsxK07hsIZPa2x54bA",
"kid":"BF9-zDWEjtezwBLqdhRCLw"
}
],
"type":"temporary"
}

In this case, there is nothing extra you have to do with ExoPlayer. Contents will be played fine, and this is the way ExoPlayer recommended. (https://exoplayer.dev/drm.html)

You can simply simulate this response by implementing MediaDrmCallback.

MediaDrmCallback for case1

Case 2: License server responds with the requested key only

// request
{
"kids":[
"x3_uNeUf1hWnuRr8sQkcXg" // video kid
],
"type":"temporary"
}
// response
{
"keys":[
{
"kty":"oct",
"k":"7s2ytUnwKnyXzlDBf0lMoA",
"kid":"x3_uNeUf1hWnuRr8sQkcXg"
}
],
"type":"temporary"
}

If you use multi-key and your license server responses like this, you have to enable multisession=true in DefaultDrmSessionManager.java to play this content. However, note that adaptation between streams that use different keys will not be completely seamless. (https://github.com/google/ExoPlayer/issues/4133)

This is how you simulate the license response.

The topic I wrote is well-described in this page. So, I will recommend you to check this out if you want to know more.

Reference

https://exoplayer.dev/drm.html

https://github.com/google/ExoPlayer/issues/4133

Written by

Android Engineer at AbemaTV Github: https://github.com/takusemba

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store