From 266e5a6408a5e1a2e385a859bddfdd90320a3a7d Mon Sep 17 00:00:00 2001 From: Simon Gingras Date: Wed, 8 Feb 2023 14:05:10 -0500 Subject: [PATCH 1/3] fix(IMA): Prevent replaying the content after Postroll ads --- lib/ads/client_side_ad_manager.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/ads/client_side_ad_manager.js b/lib/ads/client_side_ad_manager.js index 4f5931329a..d710477d02 100644 --- a/lib/ads/client_side_ad_manager.js +++ b/lib/ads/client_side_ad_manager.js @@ -48,6 +48,9 @@ shaka.ads.ClientSideAdManager = class { /** @private {shaka.util.EventManager} */ this.eventManager_ = new shaka.util.EventManager(); + /** @private {boolean} */ + this.contentCompletedCalled_ = false; + google.ima.settings.setLocale(locale); const adDisplayContainer = new google.ima.AdDisplayContainer( @@ -80,6 +83,7 @@ shaka.ads.ClientSideAdManager = class { // Notify the SDK when the video has ended, so it can play post-roll ads. this.video_.onended = () => { + this.contentCompletedCalled_ = true; this.adsLoader_.contentComplete(); }; } @@ -154,6 +158,7 @@ shaka.ads.ClientSideAdManager = class { (new Map()).set('loadTime', loadTime))); this.imaAdsManager_ = e.getAdsManager(this.video_); + this.contentCompletedCalled_ = false; this.onEvent_(new shaka.util.FakeEvent( shaka.ads.AdManager.IMA_AD_MANAGER_LOADED, @@ -452,7 +457,9 @@ shaka.ads.ClientSideAdManager = class { (new Map()).set('originalEvent', e))); if (this.ad_ && this.ad_.isLinear()) { this.adContainer_.removeAttribute('ad-active'); - this.video_.play(); + if (!this.contentCompletedCalled_) { + this.video_.play(); + } } } }; From 8154c490968bc9e07b01cb4e8f2cbf64321a7206 Mon Sep 17 00:00:00 2001 From: Simon Gingras Date: Wed, 8 Feb 2023 14:49:21 -0500 Subject: [PATCH 2/3] Rerun check From 94f5d64ba4c0341c4a1d834200e01917deebd737 Mon Sep 17 00:00:00 2001 From: Simon Gingras Date: Wed, 8 Feb 2023 21:27:41 -0500 Subject: [PATCH 3/3] Use video element ended property instead of an internal flag --- lib/ads/client_side_ad_manager.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/ads/client_side_ad_manager.js b/lib/ads/client_side_ad_manager.js index d710477d02..58e18758e2 100644 --- a/lib/ads/client_side_ad_manager.js +++ b/lib/ads/client_side_ad_manager.js @@ -48,9 +48,6 @@ shaka.ads.ClientSideAdManager = class { /** @private {shaka.util.EventManager} */ this.eventManager_ = new shaka.util.EventManager(); - /** @private {boolean} */ - this.contentCompletedCalled_ = false; - google.ima.settings.setLocale(locale); const adDisplayContainer = new google.ima.AdDisplayContainer( @@ -83,7 +80,6 @@ shaka.ads.ClientSideAdManager = class { // Notify the SDK when the video has ended, so it can play post-roll ads. this.video_.onended = () => { - this.contentCompletedCalled_ = true; this.adsLoader_.contentComplete(); }; } @@ -158,7 +154,6 @@ shaka.ads.ClientSideAdManager = class { (new Map()).set('loadTime', loadTime))); this.imaAdsManager_ = e.getAdsManager(this.video_); - this.contentCompletedCalled_ = false; this.onEvent_(new shaka.util.FakeEvent( shaka.ads.AdManager.IMA_AD_MANAGER_LOADED, @@ -457,7 +452,7 @@ shaka.ads.ClientSideAdManager = class { (new Map()).set('originalEvent', e))); if (this.ad_ && this.ad_.isLinear()) { this.adContainer_.removeAttribute('ad-active'); - if (!this.contentCompletedCalled_) { + if (!this.video_.ended) { this.video_.play(); } }