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.
This commit is contained in:
Álvaro Velad Galván
2024-10-23 21:31:51 +02:00
committed by GitHub
parent 4e6e37c0ce
commit ad9f2ac039
+16 -1
View File
@@ -680,11 +680,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)) {