diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 7f1f1930dd4..a43242ab8a4 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -16,6 +16,8 @@ [#6798](https://github.com/google/ExoPlayer/issues/6798)). * Fix `DownloadHelper.createMediaSource` to use `customCacheKey` when creating `ProgressiveMediaSource` instances. +* DRM: Fix `NullPointerException` when playing DRM-protected content + ([#6951](https://github.com/google/ExoPlayer/issues/6951)). * Metadata: * Update `IcyDecoder` to try ISO-8859-1 decoding if UTF-8 decoding fails. Also change `IcyInfo.rawMetadata` from `String` to `byte[]` to allow diff --git a/demos/main/src/main/assets/media.exolist.json b/demos/main/src/main/assets/media.exolist.json index 4375bdf3a78..d1acc3f3d16 100644 --- a/demos/main/src/main/assets/media.exolist.json +++ b/demos/main/src/main/assets/media.exolist.json @@ -3,9 +3,8 @@ "name": "YouTube DASH", "samples": [ { - "name": "Google Glass (MP4,H264)", - "uri": "https://www.youtube.com/api/manifest/dash/id/bf5bb2419360daf1/source/youtube?as=fmp4_audio_clear,fmp4_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=51AF5F39AB0CEC3E5497CD9C900EBFEAECCCB5C7.8506521BFC350652163895D4C26DEE124209AA9E&key=ik0", - "extension": "mpd" + "name": "6956", + "uri": "http://master255.org/res/%d0%9a%d0%bb%d0%b8%d0%bf%d1%8b/B/Billy%20Mack/Billy%20Mack%20-%20Christmas%20Is%20All%20Around.mpg" }, { "name": "Google Play (MP4,H264)", diff --git a/library/core/src/main/java/com/google/android/exoplayer2/audio/SimpleDecoderAudioRenderer.java b/library/core/src/main/java/com/google/android/exoplayer2/audio/SimpleDecoderAudioRenderer.java index 39776501462..30c664f0f84 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/audio/SimpleDecoderAudioRenderer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/audio/SimpleDecoderAudioRenderer.java @@ -97,6 +97,7 @@ public abstract class SimpleDecoderAudioRenderer extends BaseRenderer implements private final AudioSink audioSink; private final DecoderInputBuffer flagsOnlyBuffer; + private boolean drmResourcesAcquired; private DecoderCounters decoderCounters; private Format inputFormat; private int encoderDelay; @@ -539,6 +540,10 @@ public PlaybackParameters getPlaybackParameters() { @Override protected void onEnabled(boolean joining) throws ExoPlaybackException { + if (drmSessionManager != null && !drmResourcesAcquired) { + drmResourcesAcquired = true; + drmSessionManager.prepare(); + } decoderCounters = new DecoderCounters(); eventDispatcher.enabled(decoderCounters); int tunnelingAudioSessionId = getConfiguration().tunnelingAudioSessionId; @@ -587,6 +592,14 @@ protected void onDisabled() { } } + @Override + protected void onReset() { + if (drmSessionManager != null && drmResourcesAcquired) { + drmResourcesAcquired = false; + drmSessionManager.release(); + } + } + @Override public void handleMessage(int messageType, @Nullable Object message) throws ExoPlaybackException { switch (messageType) { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java index a0530dd19b5..4830b787605 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java @@ -325,6 +325,7 @@ private static String getDiagnosticInfoV21(Throwable cause) { private final ArrayList decodeOnlyPresentationTimestamps; private final MediaCodec.BufferInfo outputBufferInfo; + private boolean drmResourcesAcquired; @Nullable private Format inputFormat; private Format outputFormat; @Nullable private DrmSession codecDrmSession; @@ -597,6 +598,10 @@ protected final MediaCodec getCodec() { @Override protected void onEnabled(boolean joining) throws ExoPlaybackException { + if (drmSessionManager != null && !drmResourcesAcquired) { + drmResourcesAcquired = true; + drmSessionManager.prepare(); + } decoderCounters = new DecoderCounters(); } @@ -637,6 +642,10 @@ protected void onReset() { } finally { setSourceDrmSession(null); } + if (drmSessionManager != null && drmResourcesAcquired) { + drmResourcesAcquired = false; + drmSessionManager.release(); + } } protected void releaseCodec() { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/video/SimpleDecoderVideoRenderer.java b/library/core/src/main/java/com/google/android/exoplayer2/video/SimpleDecoderVideoRenderer.java index bf0a28ffa0c..6d8147b012e 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/video/SimpleDecoderVideoRenderer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/video/SimpleDecoderVideoRenderer.java @@ -77,6 +77,7 @@ public abstract class SimpleDecoderVideoRenderer extends BaseRenderer { private final DecoderInputBuffer flagsOnlyBuffer; private final DrmSessionManager drmSessionManager; + private boolean drmResourcesAcquired; private Format inputFormat; private Format outputFormat; private SimpleDecoder< @@ -237,6 +238,10 @@ public boolean isReady() { @Override protected void onEnabled(boolean joining) throws ExoPlaybackException { + if (drmSessionManager != null && !drmResourcesAcquired) { + drmResourcesAcquired = true; + drmSessionManager.prepare(); + } decoderCounters = new DecoderCounters(); eventDispatcher.enabled(decoderCounters); } @@ -286,6 +291,14 @@ protected void onDisabled() { } } + @Override + protected void onReset() { + if (drmSessionManager != null && drmResourcesAcquired) { + drmResourcesAcquired = false; + drmSessionManager.release(); + } + } + @Override protected void onStreamChanged(Format[] formats, long offsetUs) throws ExoPlaybackException { outputStreamOffsetUs = offsetUs;