From 33b9daabc9d6cf6e70ccc6f68f4c0f18525232df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=CC=81lvaro=20Velad=20Galva=CC=81n?= Date: Tue, 5 Nov 2024 11:35:45 +0100 Subject: [PATCH 1/2] fix(Ads): Allow play interstitials on iOS fullscreen --- lib/ads/interstitial_ad_manager.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/ads/interstitial_ad_manager.js b/lib/ads/interstitial_ad_manager.js index 91c1f3707f..7a86890b49 100644 --- a/lib/ads/interstitial_ad_manager.js +++ b/lib/ads/interstitial_ad_manager.js @@ -39,6 +39,9 @@ shaka.ads.InterstitialAdManager = class { * @param {function(!shaka.util.FakeEvent)} onEvent */ constructor(adContainer, basePlayer, baseVideo, onEvent) { + /** @private {?shaka.extern.AdsConfiguration} */ + this.config_ = null; + /** @private {HTMLElement} */ this.adContainer_ = adContainer; @@ -197,11 +200,26 @@ shaka.ads.InterstitialAdManager = class { * @param {shaka.extern.AdsConfiguration} config */ configure(config) { - if (!this.adContainer_ || - this.usingBaseVideo_ != config.supportsMultipleMediaElements) { + this.config_ = config; + } + + /** + * @private + */ + checkSupportForMultipleMediaElements_() { + if (!this.adContainer_ || !this.config_ || this.playingAd_) { + return; + } + let supportsMultipleMediaElements = + this.config_.supportsMultipleMediaElements; + const video = /** @type {HTMLVideoElement} */(this.baseVideo_); + if (video.webkitSupportsFullscreen && video.webkitDisplayingFullscreen) { + supportsMultipleMediaElements = false; + } + if (this.usingBaseVideo_ != supportsMultipleMediaElements) { return; } - this.usingBaseVideo_ = !config.supportsMultipleMediaElements; + this.usingBaseVideo_ = !supportsMultipleMediaElements; if (this.usingBaseVideo_) { this.video_ = this.baseVideo_; if (this.adVideo_) { @@ -491,6 +509,7 @@ shaka.ads.InterstitialAdManager = class { */ async setupAd_(interstitial, sequenceLength, adPosition, initialTime, oncePlayed = 0) { + this.checkSupportForMultipleMediaElements_(); goog.asserts.assert(this.video_, 'Must have video'); this.lastPlayedAd_ = interstitial; @@ -618,6 +637,7 @@ shaka.ads.InterstitialAdManager = class { this.baseVideo_.play(); } } + this.checkSupportForMultipleMediaElements_(); } }; const error = async (e) => { From 4124639f46a9dd47e9da5b3b286f4e8c9ec68b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=CC=81lvaro=20Velad=20Galva=CC=81n?= Date: Wed, 6 Nov 2024 09:50:20 +0100 Subject: [PATCH 2/2] Rename to determineIfUsingBaseVideo_ --- lib/ads/interstitial_ad_manager.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ads/interstitial_ad_manager.js b/lib/ads/interstitial_ad_manager.js index 7a86890b49..1fba90c5a8 100644 --- a/lib/ads/interstitial_ad_manager.js +++ b/lib/ads/interstitial_ad_manager.js @@ -206,7 +206,7 @@ shaka.ads.InterstitialAdManager = class { /** * @private */ - checkSupportForMultipleMediaElements_() { + determineIfUsingBaseVideo_() { if (!this.adContainer_ || !this.config_ || this.playingAd_) { return; } @@ -509,7 +509,7 @@ shaka.ads.InterstitialAdManager = class { */ async setupAd_(interstitial, sequenceLength, adPosition, initialTime, oncePlayed = 0) { - this.checkSupportForMultipleMediaElements_(); + this.determineIfUsingBaseVideo_(); goog.asserts.assert(this.video_, 'Must have video'); this.lastPlayedAd_ = interstitial; @@ -637,7 +637,7 @@ shaka.ads.InterstitialAdManager = class { this.baseVideo_.play(); } } - this.checkSupportForMultipleMediaElements_(); + this.determineIfUsingBaseVideo_(); } }; const error = async (e) => {