From 17232f58a339809279c0d7f8432a8014ce72309b Mon Sep 17 00:00:00 2001 From: olly Date: Wed, 6 Sep 2017 03:51:04 -0700 Subject: [PATCH] Fix position reporting during ads when period has non-zero window offset. 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 --- .../exoplayer2/ext/ima/ImaAdsLoader.java | 4 +++- .../android/exoplayer2/ExoPlayerImpl.java | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoader.java b/extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoader.java index c27ef17b872..87033173def 100644 --- a/extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoader.java +++ b/extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoader.java @@ -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); } } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java index 7bf0cd5a028..e574bfc1eed 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java @@ -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); } } @@ -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); } } @@ -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 @@ -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; + } + }