Skip to content

Commit

Permalink
fix(Ads): Limit static overlay playback to the timeline (#7741)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored Dec 11, 2024
1 parent 775bc4e commit eff0aef
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions lib/ads/interstitial_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,11 +725,6 @@ shaka.ads.InterstitialAdManager = class {
* @private
*/
setupStaticAd_(interstitial, sequenceLength, adPosition, oncePlayed) {
let duration = interstitial.playoutLimit;
if (interstitial.endTime) {
duration = interstitial.endTime - interstitial.startTime;
}

const overlay = interstitial.overlay;
goog.asserts.assert(overlay, 'Must have overlay');

Expand Down Expand Up @@ -800,15 +795,31 @@ shaka.ads.InterstitialAdManager = class {
}
this.adContainer_.appendChild(htmlElement);

if (duration) {
if (this.playoutLimitTimer_) {
this.playoutLimitTimer_.stop();
}
this.playoutLimitTimer_ = new shaka.util.Timer(() => {
const startTime = Date.now();
if (this.playoutLimitTimer_) {
this.playoutLimitTimer_.stop();
}
this.playoutLimitTimer_ = new shaka.util.Timer(() => {
if (interstitial.playoutLimit &&
(Date.now() - startTime) / 1000 > interstitial.playoutLimit) {
this.onEvent_(
new shaka.util.FakeEvent(shaka.ads.Utils.AD_COMPLETE));
basicTask();
} else if (interstitial.endTime &&
this.baseVideo_.currentTime > interstitial.endTime) {
this.onEvent_(
new shaka.util.FakeEvent(shaka.ads.Utils.AD_COMPLETE));
basicTask();
}).tickAfter(duration);
} else if (this.baseVideo_.currentTime < interstitial.startTime) {
this.onEvent_(
new shaka.util.FakeEvent(shaka.ads.Utils.AD_SKIPPED));
basicTask();
}
});
if (interstitial.playoutLimit && !interstitial.endTime) {
this.playoutLimitTimer_.tickAfter(interstitial.playoutLimit);
} else if (interstitial.endTime) {
this.playoutLimitTimer_.tickEvery(/* seconds= */ 0.025);
}
}

Expand Down

0 comments on commit eff0aef

Please sign in to comment.