From a99295b364d86d9113addc34ff5ff503343f9d40 Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Thu, 7 Dec 2017 06:38:39 -0800 Subject: [PATCH] Fix ad loading when there is no preroll ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=178234009 --- RELEASENOTES.md | 1 + .../android/exoplayer2/ext/ima/ImaAdsLoader.java | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index a7199301d7..e4a0b40b23 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -25,6 +25,7 @@ * IMA extension: * Skip ads before the ad preceding the player's initial seek position ([#3527](https://github.com/google/ExoPlayer/issues/3527)). + * Fix ad loading when there is no preroll. ### 2.6.0 ### 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 58268d5670..0fa34e5144 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 @@ -326,9 +326,13 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A adsRenderingSettings.setMimeTypes(supportedMimeTypes); int adGroupIndexForPosition = getAdGroupIndexForPosition(adGroupTimesUs, C.msToUs(pendingContentPositionMs)); - if (adGroupIndexForPosition == C.INDEX_UNSET) { + if (adGroupIndexForPosition == 0) { + podIndexOffset = 0; + } else if (adGroupIndexForPosition == C.INDEX_UNSET) { pendingContentPositionMs = C.TIME_UNSET; - } else if (adGroupIndexForPosition > 0) { + // There is no preroll and midroll pod indices start at 1. + podIndexOffset = -1; + } else /* adGroupIndexForPosition > 0 */ { // Skip ad groups before the one at or immediately before the playback position. for (int i = 0; i < adGroupIndexForPosition; i++) { adPlaybackState.playedAdGroup(i); @@ -341,8 +345,7 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A adsRenderingSettings.setPlayAdsAfterTime(midpointTimeUs / C.MICROS_PER_SECOND); // We're removing one or more ads, which means that the earliest ad (if any) will be a - // midroll/postroll. According to the AdPodInfo documentation, midroll pod indices always - // start at 1, so take this into account when offsetting the pod index for the skipped ads. + // midroll/postroll. Midroll pod indices start at 1. podIndexOffset = adGroupIndexForPosition - 1; }