Tighten the demo app's handling of DrmInitData
for downloads
This code is Widevine specific. `OfflineLicenseHelper.downloadLicense` requires the passed `Format` to have a `DrmInitData.SchemeData` with Widevine UUID and non-null `data` field. The demo app tries to check this in advance (to avoid an exception later), but its checks are looser than those made by `OfflineLicenseHelper`. This change tightens the checks to match. Issue: androidx/media#512 PiperOrigin-RevId: 549587506
This commit is contained in:
parent
f4c66d82dd
commit
1ccedf8414
@ -26,6 +26,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.annotation.OptIn;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.media3.common.C;
|
||||
import androidx.media3.common.DrmInitData;
|
||||
import androidx.media3.common.Format;
|
||||
import androidx.media3.common.MediaItem;
|
||||
@ -51,6 +52,7 @@ import androidx.media3.exoplayer.source.TrackGroupArray;
|
||||
import androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
/** Tracks media that has been downloaded. */
|
||||
@ -202,7 +204,7 @@ public class DownloadTracker {
|
||||
return;
|
||||
}
|
||||
// TODO(internal b/163107948): Support cases where DrmInitData are not in the manifest.
|
||||
if (!hasSchemaData(format.drmInitData)) {
|
||||
if (!hasNonNullWidevineSchemaData(format.drmInitData)) {
|
||||
Toast.makeText(context, R.string.download_start_error_offline_license, Toast.LENGTH_LONG)
|
||||
.show();
|
||||
Log.e(
|
||||
@ -323,12 +325,14 @@ public class DownloadTracker {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether any the {@link DrmInitData.SchemeData} contained in {@code drmInitData} has
|
||||
* non-null {@link DrmInitData.SchemeData#data}.
|
||||
* Returns whether any {@link DrmInitData.SchemeData} that {@linkplain
|
||||
* DrmInitData.SchemeData#matches(UUID) matches} {@link C#WIDEVINE_UUID} has non-null {@link
|
||||
* DrmInitData.SchemeData#data}.
|
||||
*/
|
||||
private boolean hasSchemaData(DrmInitData drmInitData) {
|
||||
private boolean hasNonNullWidevineSchemaData(DrmInitData drmInitData) {
|
||||
for (int i = 0; i < drmInitData.schemeDataCount; i++) {
|
||||
if (drmInitData.get(i).hasData()) {
|
||||
DrmInitData.SchemeData schemeData = drmInitData.get(i);
|
||||
if (schemeData.matches(C.WIDEVINE_UUID) && schemeData.hasData()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user