Skip to content

Commit

Permalink
Prevent NPE in ImaAdsLoader onPositionDiscontinuity.
Browse files Browse the repository at this point in the history
Any seek before the first timeline becomes available will result in a NPE.
Change it to handle that case gracefully.

Issue:#5831
PiperOrigin-RevId: 264603061
  • Loading branch information
tonihei authored and ojw28 committed Sep 2, 2019
1 parent 5b2b21d commit 9e3bee8
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ private ImaAdsLoader(
pendingContentPositionMs = C.TIME_UNSET;
adGroupIndex = C.INDEX_UNSET;
contentDurationMs = C.TIME_UNSET;
timeline = Timeline.EMPTY;
}

/**
Expand Down Expand Up @@ -967,7 +968,7 @@ public void onTimelineChanged(
if (contentDurationUs != C.TIME_UNSET) {
adPlaybackState = adPlaybackState.withContentDurationUs(contentDurationUs);
}
updateImaStateForPlayerState();
onPositionDiscontinuity(Player.DISCONTINUITY_REASON_INTERNAL);
}

@Override
Expand Down Expand Up @@ -1022,7 +1023,7 @@ public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
}
}
updateAdPlaybackState();
} else {
} else if (!timeline.isEmpty()) {
long positionMs = player.getCurrentPosition();
timeline.getPeriod(0, period);
int newAdGroupIndex = period.getAdGroupIndexForPositionUs(C.msToUs(positionMs));
Expand All @@ -1034,9 +1035,8 @@ public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
}
}
}
} else {
updateImaStateForPlayerState();
}
updateImaStateForPlayerState();
}

// Internal methods.
Expand Down

0 comments on commit 9e3bee8

Please sign in to comment.