Skip to content

Commit

Permalink
fix(Ads): Limit interstitial duration to actual duration if available…
Browse files Browse the repository at this point in the history
… when using src= (#7488)

Currently, if the interstitial lasts 30 and we have a stream that lasts
31 seconds, we would go back to live after the interstitial, but with 1
extra second of latency. This PR solves this by limiting the play range
to 30.

Related to #7480
  • Loading branch information
avelad committed Oct 24, 2024
1 parent 806dd5a commit a9a2c52
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/ads/interstitial_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,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));
});
Expand All @@ -675,12 +682,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;
Expand All @@ -692,9 +694,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)) {
Expand Down

0 comments on commit a9a2c52

Please sign in to comment.