diff --git a/lib/ads/interstitial_ad_manager.js b/lib/ads/interstitial_ad_manager.js index 6f90befd0c..d6cd0cada5 100644 --- a/lib/ads/interstitial_ad_manager.js +++ b/lib/ads/interstitial_ad_manager.js @@ -515,6 +515,13 @@ shaka.ads.InterstitialAdManager = class { new shaka.util.FakeEvent(shaka.ads.Utils.AD_RESUMED)); }); this.adEventManager_.listen(this.video_, 'pause', () => { + // playRangeEnd in src= causes the ended event not to be fired when that + // position is reached, instead pause event is fired. + const currentConfig = this.player_.getConfiguration(); + if (this.video_.currentTime >= currentConfig.playRangeEnd) { + complete(); + return; + } this.onEvent_( new shaka.util.FakeEvent(shaka.ads.Utils.AD_PAUSED)); }); @@ -529,12 +536,7 @@ shaka.ads.InterstitialAdManager = class { }); try { this.updatePlayerConfig_(); - // playRangeEnd in src= causes the ended event not to be fired when that - // position is reached. So we don't use it because we would never go back - // to the main stream. - const loadMode = this.basePlayer_.getLoadMode(); - if (loadMode == shaka.Player.LoadMode.MEDIA_SOURCE && - interstitial.startTime && interstitial.endTime && + if (interstitial.startTime && interstitial.endTime && interstitial.endTime != Infinity && interstitial.startTime != interstitial.endTime) { const duration = interstitial.endTime - interstitial.startTime; @@ -546,9 +548,7 @@ shaka.ads.InterstitialAdManager = class { playoutLimitTimer = new shaka.util.Timer(() => { ad.skip(); }).tickAfter(interstitial.playoutLimit); - if (loadMode == shaka.Player.LoadMode.MEDIA_SOURCE) { - this.player_.configure('playRangeEnd', interstitial.playoutLimit); - } + this.player_.configure('playRangeEnd', interstitial.playoutLimit); } await this.player_.attach(this.video_); if (this.preloadManagerInterstitials_.has(interstitial)) {