diff --git a/lib/ads/interstitial_ad_manager.js b/lib/ads/interstitial_ad_manager.js index 9f6f40bde8..229c2c4c0e 100644 --- a/lib/ads/interstitial_ad_manager.js +++ b/lib/ads/interstitial_ad_manager.js @@ -675,11 +675,26 @@ 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 && + interstitial.endTime != Infinity && + interstitial.startTime != interstitial.endTime) { + const duration = interstitial.endTime - interstitial.startTime; + if (duration > 0) { + this.player_.configure('playRangeEnd', duration); + } + } if (interstitial.playoutLimit) { playoutLimitTimer = new shaka.util.Timer(() => { ad.skip(); }).tickAfter(interstitial.playoutLimit); - this.player_.configure('playRangeEnd', interstitial.playoutLimit); + if (loadMode == shaka.Player.LoadMode.MEDIA_SOURCE) { + this.player_.configure('playRangeEnd', interstitial.playoutLimit); + } } await this.player_.attach(this.video_); if (this.preloadManagerInterstitials_.has(interstitial)) {