diff --git a/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSession.java b/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSession.java index aa29dc7504..d6a28ed2e8 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSession.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSession.java @@ -30,6 +30,7 @@ import androidx.annotation.GuardedBy; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import com.google.android.exoplayer2.C; +import com.google.android.exoplayer2.PlaybackException; import com.google.android.exoplayer2.drm.DrmInitData.SchemeData; import com.google.android.exoplayer2.drm.ExoMediaDrm.KeyRequest; import com.google.android.exoplayer2.drm.ExoMediaDrm.ProvisionRequest; @@ -511,7 +512,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; } private void onError(final Exception e) { - lastException = new DrmSessionException(e); + // TODO(internal b/184262323): Add an argument here which takes the error code from the caller. + lastException = new DrmSessionException(e, PlaybackException.ERROR_CODE_DRM_UNSPECIFIED); Log.e(TAG, "DRM session error", e); dispatchEvent(eventDispatcher -> eventDispatcher.drmSessionManagerError(e)); if (state != STATE_OPENED_WITH_KEYS) { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSessionManager.java b/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSessionManager.java index f347cdae80..9b4b290459 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSessionManager.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSessionManager.java @@ -30,6 +30,7 @@ import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; +import com.google.android.exoplayer2.PlaybackException; import com.google.android.exoplayer2.drm.DrmInitData.SchemeData; import com.google.android.exoplayer2.drm.DrmSession.DrmSessionException; import com.google.android.exoplayer2.drm.ExoMediaDrm.OnEventListener; @@ -540,7 +541,8 @@ public class DefaultDrmSessionManager implements DrmSessionManager { if (eventDispatcher != null) { eventDispatcher.drmSessionManagerError(error); } - return new ErrorStateDrmSession(new DrmSessionException(error)); + return new ErrorStateDrmSession( + new DrmSessionException(error, PlaybackException.ERROR_CODE_DRM_CONTENT_ERROR)); } } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/drm/DrmSession.java b/library/core/src/main/java/com/google/android/exoplayer2/drm/DrmSession.java index 954bdd86c4..b993345613 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/drm/DrmSession.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/drm/DrmSession.java @@ -18,6 +18,7 @@ package com.google.android.exoplayer2.drm; import android.media.MediaDrm; import androidx.annotation.IntDef; import androidx.annotation.Nullable; +import com.google.android.exoplayer2.PlaybackException; import java.io.IOException; import java.lang.annotation.Documented; import java.lang.annotation.Retention; @@ -53,8 +54,12 @@ public interface DrmSession { /** Wraps the throwable which is the cause of the error state. */ class DrmSessionException extends IOException { - public DrmSessionException(Throwable cause) { + /** The {@link PlaybackException.ErrorCode} that corresponds to the failure. */ + @PlaybackException.ErrorCode public final int errorCode; + + public DrmSessionException(Throwable cause, @PlaybackException.ErrorCode int errorCode) { super(cause); + this.errorCode = errorCode; } } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/drm/DrmSessionManager.java b/library/core/src/main/java/com/google/android/exoplayer2/drm/DrmSessionManager.java index 4b3ee553d8..b056f6ab0d 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/drm/DrmSessionManager.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/drm/DrmSessionManager.java @@ -18,6 +18,7 @@ package com.google.android.exoplayer2.drm; import android.os.Looper; import androidx.annotation.Nullable; import com.google.android.exoplayer2.Format; +import com.google.android.exoplayer2.PlaybackException; /** Manages a DRM session. */ public interface DrmSessionManager { @@ -54,8 +55,8 @@ public interface DrmSessionManager { } else { return new ErrorStateDrmSession( new DrmSession.DrmSessionException( - new UnsupportedDrmException( - UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME))); + new UnsupportedDrmException(UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME), + PlaybackException.ERROR_CODE_DRM_SCHEME_UNSUPPORTED)); } } diff --git a/library/core/src/test/java/com/google/android/exoplayer2/source/SampleQueueTest.java b/library/core/src/test/java/com/google/android/exoplayer2/source/SampleQueueTest.java index 317ddceb05..ce8b839d7f 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/source/SampleQueueTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/source/SampleQueueTest.java @@ -35,6 +35,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.FormatHolder; +import com.google.android.exoplayer2.PlaybackException; import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.drm.DrmInitData; import com.google.android.exoplayer2.drm.DrmSession; @@ -554,7 +555,10 @@ public final class SampleQueueTest { assertReadNothing(/* formatRequired= */ false); sampleQueue.maybeThrowError(); when(mockDrmSession.getState()).thenReturn(DrmSession.STATE_ERROR); - when(mockDrmSession.getError()).thenReturn(new DrmSession.DrmSessionException(new Exception())); + when(mockDrmSession.getError()) + .thenReturn( + new DrmSession.DrmSessionException( + new Exception(), PlaybackException.ERROR_CODE_DRM_UNSPECIFIED)); assertReadNothing(/* formatRequired= */ false); try { sampleQueue.maybeThrowError();