Commit 56feb96f by andrewlewis Committed by Oliver Woodman

Handle loading the same ad more than once

Also allow the player's prepared ad media period durations array to exceed the
length of the loaded ad URIs array, as it's possible for the player to buffer
an ad media period fully at the point where it's known that an ad is coming up
but its URI is still unknown.

PiperOrigin-RevId: 356249284
parent 5211f06d
...@@ -5,6 +5,12 @@ ...@@ -5,6 +5,12 @@
* Core library: * Core library:
* Fix playback issue for HLS live streams without program date time * Fix playback issue for HLS live streams without program date time
information ([#8560](https://github.com/google/ExoPlayer/issues/8560)). information ([#8560](https://github.com/google/ExoPlayer/issues/8560)).
* IMA extension:
* Fix handling of repeated ad loads, to avoid ads being discarded if the
user seeks away and then back to a preloaded postroll (for example).
* Fix a bug where an assertion would fail if the player started to buffer
an ad media period before the ad URI was known then an ad state update
arrived that didn't set the ad URI.
### 2.13.0 (2021-02-04) ### 2.13.0 (2021-02-04)
......
...@@ -879,7 +879,8 @@ import java.util.Map; ...@@ -879,7 +879,8 @@ import java.util.Map;
int adGroupIndex = getAdGroupIndexForAdPod(adPodInfo); int adGroupIndex = getAdGroupIndexForAdPod(adPodInfo);
int adIndexInAdGroup = adPodInfo.getAdPosition() - 1; int adIndexInAdGroup = adPodInfo.getAdPosition() - 1;
AdInfo adInfo = new AdInfo(adGroupIndex, adIndexInAdGroup); AdInfo adInfo = new AdInfo(adGroupIndex, adIndexInAdGroup);
adInfoByAdMediaInfo.put(adMediaInfo, adInfo); // The ad URI may already be known, so force put to update it if needed.
adInfoByAdMediaInfo.forcePut(adMediaInfo, adInfo);
if (configuration.debugModeEnabled) { if (configuration.debugModeEnabled) {
Log.d(TAG, "loadAd " + getAdMediaInfoString(adMediaInfo)); Log.d(TAG, "loadAd " + getAdMediaInfoString(adMediaInfo));
} }
......
...@@ -182,9 +182,10 @@ public final class AdPlaybackState { ...@@ -182,9 +182,10 @@ public final class AdPlaybackState {
/** Returns a new instance with the specified ad durations, in microseconds. */ /** Returns a new instance with the specified ad durations, in microseconds. */
@CheckResult @CheckResult
public AdGroup withAdDurationsUs(long[] durationsUs) { public AdGroup withAdDurationsUs(long[] durationsUs) {
Assertions.checkArgument(count == C.LENGTH_UNSET || durationsUs.length <= this.uris.length); if (durationsUs.length < uris.length) {
if (durationsUs.length < this.uris.length) {
durationsUs = copyDurationsUsWithSpaceForAdCount(durationsUs, uris.length); durationsUs = copyDurationsUsWithSpaceForAdCount(durationsUs, uris.length);
} else if (count != C.LENGTH_UNSET && durationsUs.length > uris.length) {
durationsUs = Arrays.copyOf(durationsUs, uris.length);
} }
return new AdGroup(count, states, uris, durationsUs); return new AdGroup(count, states, uris, durationsUs);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment