Prevent NPE in ImaAdsLoader onPositionDiscontinuity.

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
This commit is contained in:
tonihei 2019-08-21 15:22:47 +01:00 committed by Oliver Woodman
parent 5b2b21da86
commit 9e3bee89e1

View File

@ -484,6 +484,7 @@ public final class ImaAdsLoader
pendingContentPositionMs = C.TIME_UNSET;
adGroupIndex = C.INDEX_UNSET;
contentDurationMs = C.TIME_UNSET;
timeline = Timeline.EMPTY;
}
/**
@ -967,7 +968,7 @@ public final class ImaAdsLoader
if (contentDurationUs != C.TIME_UNSET) {
adPlaybackState = adPlaybackState.withContentDurationUs(contentDurationUs);
}
updateImaStateForPlayerState();
onPositionDiscontinuity(Player.DISCONTINUITY_REASON_INTERNAL);
}
@Override
@ -1022,7 +1023,7 @@ public final class ImaAdsLoader
}
}
updateAdPlaybackState();
} else {
} else if (!timeline.isEmpty()) {
long positionMs = player.getCurrentPosition();
timeline.getPeriod(0, period);
int newAdGroupIndex = period.getAdGroupIndexForPositionUs(C.msToUs(positionMs));
@ -1034,9 +1035,8 @@ public final class ImaAdsLoader
}
}
}
} else {
updateImaStateForPlayerState();
}
updateImaStateForPlayerState();
}
// Internal methods.