Skip to content

Commit 40c958f

Browse files
committed
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 cb3f3e4 commit 40c958f

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
@@ -536,11 +536,26 @@ shaka.ads.InterstitialAdManager = class {
536536
});
537537
try {
538538
this.updatePlayerConfig_();
539+
// playRangeEnd in src= causes the ended event not to be fired when that
540+
// position is reached. So we don't use it because we would never go back
541+
// to the main stream.
542+
const loadMode = this.basePlayer_.getLoadMode();
543+
if (loadMode == shaka.Player.LoadMode.MEDIA_SOURCE &&
544+
interstitial.startTime && interstitial.endTime &&
545+
interstitial.endTime != Infinity &&
546+
interstitial.startTime != interstitial.endTime) {
547+
const duration = interstitial.endTime - interstitial.startTime;
548+
if (duration > 0) {
549+
this.player_.configure('playRangeEnd', duration);
550+
}
551+
}
539552
if (interstitial.playoutLimit) {
540553
playoutLimitTimer = new shaka.util.Timer(() => {
541554
ad.skip();
542555
}).tickAfter(interstitial.playoutLimit);
543-
this.player_.configure('playRangeEnd', interstitial.playoutLimit);
556+
if (loadMode == shaka.Player.LoadMode.MEDIA_SOURCE) {
557+
this.player_.configure('playRangeEnd', interstitial.playoutLimit);
558+
}
544559
}
545560
await this.player_.attach(this.video_);
546561
if (this.preloadManagerInterstitials_.has(interstitial)) {

0 commit comments

Comments
 (0)