Commit fdcee8f1 by andrewlewis Committed by Oliver Woodman

Fix detection of postroll when seeking to duration

Also mark all ads as played when the postroll plays, in the case the
player is backgrounded then resumed and the user seeks back.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=164262738
parent ba46e472
...@@ -572,16 +572,26 @@ public final class ImaAdsLoader implements Player.EventListener, VideoAdPlayer, ...@@ -572,16 +572,26 @@ public final class ImaAdsLoader implements Player.EventListener, VideoAdPlayer,
return; return;
} }
if (!playingAd && !player.isPlayingAd()) { if (!playingAd && !player.isPlayingAd()) {
long positionUs = C.msToUs(player.getCurrentPosition()); checkForContentComplete();
int adGroupIndex = timeline.getPeriod(0, period).getAdGroupIndexForPositionUs(positionUs); if (sentContentComplete) {
if (adGroupIndex != C.INDEX_UNSET) { for (int i = 0; i < adPlaybackState.adGroupCount; i++) {
if (adPlaybackState.adGroupTimesUs[i] != C.TIME_END_OF_SOURCE) {
adPlaybackState.playedAdGroup(i);
}
}
updateAdPlaybackState();
} else {
long positionMs = player.getCurrentPosition();
timeline.getPeriod(0, period);
if (period.getAdGroupIndexForPositionUs(C.msToUs(positionMs)) != C.INDEX_UNSET) {
sentPendingContentPositionMs = false; sentPendingContentPositionMs = false;
pendingContentPositionMs = player.getCurrentPosition(); pendingContentPositionMs = positionMs;
} }
return;
} }
} else {
updateImaStateForPlayerState(); updateImaStateForPlayerState();
} }
}
@Override @Override
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) { public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
...@@ -672,8 +682,8 @@ public final class ImaAdsLoader implements Player.EventListener, VideoAdPlayer, ...@@ -672,8 +682,8 @@ public final class ImaAdsLoader implements Player.EventListener, VideoAdPlayer,
} }
private void checkForContentComplete() { private void checkForContentComplete() {
if (contentDurationMs != C.TIME_UNSET if (contentDurationMs != C.TIME_UNSET && pendingContentPositionMs == C.TIME_UNSET
&& player.getCurrentPosition() + END_OF_CONTENT_POSITION_THRESHOLD_MS >= contentDurationMs && player.getContentPosition() + END_OF_CONTENT_POSITION_THRESHOLD_MS >= contentDurationMs
&& !sentContentComplete) { && !sentContentComplete) {
adsLoader.contentComplete(); adsLoader.contentComplete();
if (DEBUG) { if (DEBUG) {
......
...@@ -22,7 +22,7 @@ import com.google.android.exoplayer2.util.Assertions; ...@@ -22,7 +22,7 @@ import com.google.android.exoplayer2.util.Assertions;
/** /**
* A {@link Timeline} for sources that have ads. * A {@link Timeline} for sources that have ads.
*/ */
public final class SinglePeriodAdTimeline extends Timeline { /* package */ final class SinglePeriodAdTimeline extends Timeline {
private final Timeline contentTimeline; private final Timeline contentTimeline;
private final long[] adGroupTimesUs; private final long[] adGroupTimesUs;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment