From 075713f0e012b2287cd7b95a3219e8564cedc259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Thu, 31 Oct 2024 13:18:42 +0100 Subject: [PATCH] fix(Ads): Fix duplicate Ads when playing interstitials through native HLS player (#7527) --- lib/ads/interstitial_ad_manager.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/ads/interstitial_ad_manager.js b/lib/ads/interstitial_ad_manager.js index 2e65c5206..bf2bfdc31 100644 --- a/lib/ads/interstitial_ad_manager.js +++ b/lib/ads/interstitial_ad_manager.js @@ -367,7 +367,7 @@ shaka.ads.InterstitialAdManager = class { } let cuepointsChanged = false; for (const interstitial of interstitials) { - const interstitialId = JSON.stringify(interstitial); + const interstitialId = interstitial.id || JSON.stringify(interstitial); if (this.interstitialIds_.has(interstitialId)) { continue; } @@ -777,6 +777,16 @@ shaka.ads.InterstitialAdManager = class { if (hlsInterstitialId) { id = /** @type {string} */(hlsInterstitialId.data); } + const startTime = id == null ? + Math.floor(hlsInterstitial.startTime * 10) / 10: + hlsInterstitial.startTime; + let endTime = hlsInterstitial.endTime; + if (hlsInterstitial.endTime && hlsInterstitial.endTime != Infinity && + typeof(hlsInterstitial.endTime) == 'number') { + endTime = id == null ? + Math.floor(hlsInterstitial.endTime * 10) / 10: + hlsInterstitial.endTime; + } const restrict = hlsInterstitial.values.find((v) => v.key == 'X-RESTRICT'); let isSkippable = true; let canJump = true; @@ -851,8 +861,8 @@ shaka.ads.InterstitialAdManager = class { } interstitialsAd.push({ id, - startTime: hlsInterstitial.startTime, - endTime: hlsInterstitial.endTime, + startTime, + endTime, uri, isSkippable, skipOffset, @@ -901,8 +911,8 @@ shaka.ads.InterstitialAdManager = class { if (asset['URI']) { interstitialsAd.push({ id, - startTime: hlsInterstitial.startTime, - endTime: hlsInterstitial.endTime, + startTime, + endTime, uri: asset['URI'], isSkippable, skipOffset,