Pass drm_key_request_properties in offline DRM downloads

Pass the drm_key_request_properties specified in the json list
when donwloading thee offline Widevide license in the demo app.

PiperOrigin-RevId: 342243441
This commit is contained in:
christosts 2020-11-13 13:18:54 +00:00 committed by Christos Tsilopoulos
parent 8d84a50fa1
commit dc86b625c5
2 changed files with 17 additions and 6 deletions

View File

@ -223,7 +223,7 @@ public class DownloadTracker {
widevineOfflineLicenseFetchTask = widevineOfflineLicenseFetchTask =
new WidevineOfflineLicenseFetchTask( new WidevineOfflineLicenseFetchTask(
format, format,
mediaItem.playbackProperties.drmConfiguration.licenseUri, mediaItem.playbackProperties.drmConfiguration,
httpDataSourceFactory, httpDataSourceFactory,
/* dialogHelper= */ this, /* dialogHelper= */ this,
helper); helper);
@ -373,7 +373,7 @@ public class DownloadTracker {
private static final class WidevineOfflineLicenseFetchTask extends AsyncTask<Void, Void, Void> { private static final class WidevineOfflineLicenseFetchTask extends AsyncTask<Void, Void, Void> {
private final Format format; private final Format format;
private final Uri licenseUri; private final MediaItem.DrmConfiguration drmConfiguration;
private final HttpDataSource.Factory httpDataSourceFactory; private final HttpDataSource.Factory httpDataSourceFactory;
private final StartDownloadDialogHelper dialogHelper; private final StartDownloadDialogHelper dialogHelper;
private final DownloadHelper downloadHelper; private final DownloadHelper downloadHelper;
@ -383,12 +383,12 @@ public class DownloadTracker {
public WidevineOfflineLicenseFetchTask( public WidevineOfflineLicenseFetchTask(
Format format, Format format,
Uri licenseUri, MediaItem.DrmConfiguration drmConfiguration,
HttpDataSource.Factory httpDataSourceFactory, HttpDataSource.Factory httpDataSourceFactory,
StartDownloadDialogHelper dialogHelper, StartDownloadDialogHelper dialogHelper,
DownloadHelper downloadHelper) { DownloadHelper downloadHelper) {
this.format = format; this.format = format;
this.licenseUri = licenseUri; this.drmConfiguration = drmConfiguration;
this.httpDataSourceFactory = httpDataSourceFactory; this.httpDataSourceFactory = httpDataSourceFactory;
this.dialogHelper = dialogHelper; this.dialogHelper = dialogHelper;
this.downloadHelper = downloadHelper; this.downloadHelper = downloadHelper;
@ -398,8 +398,10 @@ public class DownloadTracker {
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
OfflineLicenseHelper offlineLicenseHelper = OfflineLicenseHelper offlineLicenseHelper =
OfflineLicenseHelper.newWidevineInstance( OfflineLicenseHelper.newWidevineInstance(
licenseUri.toString(), drmConfiguration.licenseUri.toString(),
drmConfiguration.forceDefaultLicenseUri,
httpDataSourceFactory, httpDataSourceFactory,
drmConfiguration.requestHeaders,
new DrmSessionEventListener.EventDispatcher()); new DrmSessionEventListener.EventDispatcher());
try { try {
keySetId = offlineLicenseHelper.downloadLicense(format); keySetId = offlineLicenseHelper.downloadLicense(format);

View File

@ -64,6 +64,7 @@ import java.net.CookiePolicy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
/** An activity that plays media using {@link SimpleExoPlayer}. */ /** An activity that plays media using {@link SimpleExoPlayer}. */
public class PlayerActivity extends AppCompatActivity public class PlayerActivity extends AppCompatActivity
@ -535,7 +536,9 @@ public class PlayerActivity extends AppCompatActivity
.setCustomCacheKey(downloadRequest.customCacheKey) .setCustomCacheKey(downloadRequest.customCacheKey)
.setMimeType(downloadRequest.mimeType) .setMimeType(downloadRequest.mimeType)
.setStreamKeys(downloadRequest.streamKeys) .setStreamKeys(downloadRequest.streamKeys)
.setDrmKeySetId(downloadRequest.keySetId); .setDrmKeySetId(downloadRequest.keySetId)
.setDrmLicenseRequestHeaders(getDrmRequestHeaders(item));
mediaItems.add(builder.build()); mediaItems.add(builder.build());
} else { } else {
mediaItems.add(item); mediaItems.add(item);
@ -543,4 +546,10 @@ public class PlayerActivity extends AppCompatActivity
} }
return mediaItems; return mediaItems;
} }
@Nullable
private static Map<String, String> getDrmRequestHeaders(MediaItem item) {
MediaItem.DrmConfiguration drmConfiguration = item.playbackProperties.drmConfiguration;
return drmConfiguration != null ? drmConfiguration.requestHeaders : null;
}
} }