Skip to content

Commit

Permalink
Fix position reporting during ads when period has non-zero window off…
Browse files Browse the repository at this point in the history
…set.

Reporting incorrect positions for ad playbacks was causing IMA to
think the ad wasn't playing, when in fact it was.

Issue: #3180

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=167702032
  • Loading branch information
ojw28 committed Sep 6, 2017
1 parent 8ef6a2e commit 17232f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ public VideoProgressUpdate getAdProgress() {
} else if (!playingAd) {
return VideoProgressUpdate.VIDEO_TIME_NOT_READY;
} else {
return new VideoProgressUpdate(player.getCurrentPosition(), player.getDuration());
long adDuration = player.getDuration();
return adDuration == C.TIME_UNSET ? VideoProgressUpdate.VIDEO_TIME_NOT_READY
: new VideoProgressUpdate(player.getCurrentPosition(), adDuration);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,7 @@ public long getCurrentPosition() {
if (timeline.isEmpty() || pendingSeekAcks > 0) {
return maskingWindowPositionMs;
} else {
timeline.getPeriod(playbackInfo.periodId.periodIndex, period);
return period.getPositionInWindowMs() + C.usToMs(playbackInfo.positionUs);
return playbackInfoPositionUsToWindowPositionMs(playbackInfo.positionUs);
}
}

Expand All @@ -360,8 +359,7 @@ public long getBufferedPosition() {
if (timeline.isEmpty() || pendingSeekAcks > 0) {
return maskingWindowPositionMs;
} else {
timeline.getPeriod(playbackInfo.periodId.periodIndex, period);
return period.getPositionInWindowMs() + C.usToMs(playbackInfo.bufferedPositionUs);
return playbackInfoPositionUsToWindowPositionMs(playbackInfo.bufferedPositionUs);
}
}

Expand All @@ -388,7 +386,7 @@ public boolean isCurrentWindowSeekable() {

@Override
public boolean isPlayingAd() {
return pendingSeekAcks == 0 && playbackInfo.periodId.adGroupIndex != C.INDEX_UNSET;
return pendingSeekAcks == 0 && playbackInfo.periodId.isAd();
}

@Override
Expand Down Expand Up @@ -542,4 +540,13 @@ public Object getCurrentManifest() {
}
}

private long playbackInfoPositionUsToWindowPositionMs(long positionUs) {
long positionMs = C.usToMs(positionUs);
if (!playbackInfo.periodId.isAd()) {
timeline.getPeriod(playbackInfo.periodId.periodIndex, period);
positionMs += period.getPositionInWindowMs();
}
return positionMs;
}

}

0 comments on commit 17232f5

Please sign in to comment.