Verify source is not released before updating ad playback state

Updates to the ad playback state are posted on the main handler,
so they may arrive after the source has already been released
(=the internal MediaSource is null). This can cause NPEs.

PiperOrigin-RevId: 555102426
(cherry picked from commit 20d2ce7ce8)
This commit is contained in:
tonihei 2023-08-09 09:51:56 +00:00 committed by Tianyi Feng
parent 136f0876d5
commit bab04ebf2c

View file

@ -698,7 +698,9 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
@MainThread
private void invalidateServerSideAdInsertionAdPlaybackState() {
if (!adPlaybackState.equals(AdPlaybackState.NONE) && contentTimeline != null) {
if (!adPlaybackState.equals(AdPlaybackState.NONE)
&& contentTimeline != null
&& serverSideAdInsertionMediaSource != null) {
Timeline contentTimeline = checkNotNull(this.contentTimeline);
ImmutableMap<Object, AdPlaybackState> splitAdPlaybackStates;
if (Objects.equals(streamRequest.getFormat(), StreamFormat.DASH)) {