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

Taku Semba
Apr 15, 2019 · 2 min read

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

Taku Semba

Written by

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

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade