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

Taku Semba
2 min readApr 15, 2019

--

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

--

--