From 4fec24294a4e192c3bb021ab14df9f05faa3a49b Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Tue, 13 Feb 2018 01:05:08 -0800 Subject: [PATCH] Fix handling of ad tags where ad groups are out of order IMA's cue points may not be in order, so sort them. It looks like IMA events use time ordered ad indices, so it is not necessary to map between the original cue point order and the time order. Issue: #3716 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=185495798 --- RELEASENOTES.md | 2 ++ .../android/exoplayer2/ext/ima/ImaAdsLoader.java | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 4c0354fad7..bc43e8f803 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -88,6 +88,8 @@ * Add support for playing non-Extractor content MediaSources in the IMA demo app ([#3676](https://github.com/google/ExoPlayer/issues/3676)). + * Fix handling of ad tags where ad groups are out of order + ([#3716](https://github.com/google/ExoPlayer/issues/3716)). * `EventLogger` moved from the demo app into the core library. * Fix ANR issue on Huawei P8 Lite ([#3724](https://github.com/google/ExoPlayer/issues/3724)). 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 d5e120afe7..b4bbded5b9 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 @@ -970,11 +970,17 @@ public final class ImaAdsLoader extends Player.DefaultEventListener implements A int count = cuePoints.size(); long[] adGroupTimesUs = new long[count]; + int adGroupIndex = 0; for (int i = 0; i < count; i++) { double cuePoint = cuePoints.get(i); - adGroupTimesUs[i] = - cuePoint == -1.0 ? C.TIME_END_OF_SOURCE : (long) (C.MICROS_PER_SECOND * cuePoint); + if (cuePoint == -1.0) { + adGroupTimesUs[count - 1] = C.TIME_END_OF_SOURCE; + } else { + adGroupTimesUs[adGroupIndex++] = (long) (C.MICROS_PER_SECOND * cuePoint); + } } + // Cue points may be out of order, so sort them. + Arrays.sort(adGroupTimesUs, 0, adGroupIndex); return adGroupTimesUs; }