From 46387754ca494fcd0ae6cd560b9b8e3c6e3656ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Wed, 12 Jun 2024 09:59:36 +0200 Subject: [PATCH] feat(Ads): Improve preload timing on interstitials (#6792) --- lib/ads/interstitial_ad_manager.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/ads/interstitial_ad_manager.js b/lib/ads/interstitial_ad_manager.js index 4df5b8bba9..d665e1eff1 100644 --- a/lib/ads/interstitial_ad_manager.js +++ b/lib/ads/interstitial_ad_manager.js @@ -217,13 +217,19 @@ shaka.ads.InterstitialAdManager = class { } this.interstitialIds_.add(interstitialId); this.interstitials_.add(interstitialAd); - if (this.lastTime_ != null) { + let shouldPreload = false; + if (interstitialAd.startTime == 0 && !interstitialAd.canJump) { + shouldPreload = true; + } else if (this.lastTime_ != null) { const difference = interstitial.startTime - this.lastTime_; if (difference > 0 && difference <= 10) { - if (!this.preloadManagerInterstitials_.has(interstitialAd)) { - this.preloadManagerInterstitials_.set( - interstitialAd, this.player_.preload(interstitialAd.uri)); - } + shouldPreload = true; + } + } + if (shouldPreload) { + if (!this.preloadManagerInterstitials_.has(interstitialAd)) { + this.preloadManagerInterstitials_.set( + interstitialAd, this.player_.preload(interstitialAd.uri)); } } }