DefaultDrmSession should handle when key is already available (getKeyRequest() -> REQUEST_TYPE_NONE)
@icbaker is already working on this.
Since May 28, 2024.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 955
- Avg merge
- 12d 14h
- Merged PRs (30d)
- 2
Description
Use case description
When a DRM-protected (e.g. PlayReady) media file is played back for the second time, the DRM key could still be available in the DRM. Then the DRM might return REQUEST_TYPE_NONE on getKeyRequest() (see https://developer.android.com/reference/android/media/MediaDrm.KeyRequest#REQUEST_TYPE_NONE ).
DefaultDrmSession should handle this case.
Proposed solution
The proposed solution is to check the return value of getKeyRequest() and to start playback immediately, when the key is already available. See this patch:
diff --git a/exoplayer/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSession.java b/exoplayer/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSession.java
index b357a2ed06..2c93597bdf 100644
--- a/exoplayer/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSession.java
+++ b/exoplayer/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSession.java
@@ -20,6 +20,7 @@ import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull;
import static java.lang.Math.min;
import android.annotation.SuppressLint;
+import android.media.MediaDrm;
import android.media.NotProvisionedException;
import android.os.Handler;
import android.os.HandlerThread;
@@ -500,6 +501,11 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
private void postKeyRequest(byte[] scope, int type, boolean allowRetry) {
try {
currentKeyRequest = mediaDrm.getKeyRequest(scope, schemeDatas, type, keyRequestParameters);
+ if (currentKeyRequest.getRequestType() == KeyRequest.REQUEST_TYPE_NONE) {
+ state = STATE_OPENED_WITH_KEYS;
+ dispatchEvent(DrmSessionEventListener.EventDispatcher::drmKeysLoaded);
+ return;
+ }
Util.castNonNull(requestHandler)
.post(MSG_KEYS, Assertions.checkNotNull(currentKeyRequest), allowRetry);
} catch (Exception e) {
Alternatives considered
The check for REQUEST_TYPE_NONE could be done in requestHandler.post() or below, but then additional changes are necessary; especially some kind of null or empty keyResponse would need to be considered as OK/key-already-available. (IMHO not better.)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.