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
…#7480)

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.
  • Loading branch information
avelad committed Oct 24, 2024
1 parent 82f3d69 commit 9b6e40d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/ads/interstitial_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 9b6e40d

Please sign in to comment.