Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Ads): Limit interstitial duration to actual duration if available when using src= #7488

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions lib/ads/interstitial_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,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 @@ -680,12 +687,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 @@ -697,9 +699,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
Loading