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 26bbee5 commit 115fe8c
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 @@ -319,8 +319,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 @@ -330,8 +329,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 @@ -358,7 +356,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 @@ -512,4 +510,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 115fe8c

Please sign in to comment.