Skip to content

Commit ad9f2ac

Browse files
authored
fix(Ads): Limit interstitial duration to actual duration if available (#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.
1 parent 4e6e37c commit ad9f2ac

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/ads/interstitial_ad_manager.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -680,11 +680,26 @@ shaka.ads.InterstitialAdManager = class {
680680
});
681681
try {
682682
this.updatePlayerConfig_();
683+
// playRangeEnd in src= causes the ended event not to be fired when that
684+
// position is reached. So we don't use it because we would never go back
685+
// to the main stream.
686+
const loadMode = this.basePlayer_.getLoadMode();
687+
if (loadMode == shaka.Player.LoadMode.MEDIA_SOURCE &&
688+
interstitial.startTime && interstitial.endTime &&
689+
interstitial.endTime != Infinity &&
690+
interstitial.startTime != interstitial.endTime) {
691+
const duration = interstitial.endTime - interstitial.startTime;
692+
if (duration > 0) {
693+
this.player_.configure('playRangeEnd', duration);
694+
}
695+
}
683696
if (interstitial.playoutLimit) {
684697
playoutLimitTimer = new shaka.util.Timer(() => {
685698
ad.skip();
686699
}).tickAfter(interstitial.playoutLimit);
687-
this.player_.configure('playRangeEnd', interstitial.playoutLimit);
700+
if (loadMode == shaka.Player.LoadMode.MEDIA_SOURCE) {
701+
this.player_.configure('playRangeEnd', interstitial.playoutLimit);
702+
}
688703
}
689704
await this.player_.attach(this.video_);
690705
if (this.preloadManagerInterstitials_.has(interstitial)) {

0 commit comments

Comments
 (0)