diff --git a/lib/ads/interstitial_ad_manager.js b/lib/ads/interstitial_ad_manager.js index bf2bfdc312..2e61e13ad9 100644 --- a/lib/ads/interstitial_ad_manager.js +++ b/lib/ads/interstitial_ad_manager.js @@ -106,8 +106,7 @@ shaka.ads.InterstitialAdManager = class { } }); - /** @private {shaka.util.Timer} */ - this.timeUpdateTimer_ = new shaka.util.Timer(() => { + const checkForInterstitials = () => { if (this.playingAd_ || !this.lastTime_ || this.basePlayer_.isRemotePlayback()) { return; @@ -125,7 +124,22 @@ shaka.ads.InterstitialAdManager = class { this.setupAd_(currentInterstitial, /* sequenceLength= */ 1, /* adPosition= */ 1, /* initialTime= */ Date.now()); } - }).tickEvery(/* seconds= */ 0.025); + }; + + /** @private {shaka.util.Timer} */ + this.timeUpdateTimer_ = new shaka.util.Timer(checkForInterstitials); + + if ('requestVideoFrameCallback' in this.baseVideo_ && + !shaka.util.Platform.isSmartTV()) { + const baseVideo = /** @type {!HTMLVideoElement} */ (this.baseVideo_); + const videoFrameCallback = () => { + checkForInterstitials(); + baseVideo.requestVideoFrameCallback(videoFrameCallback); + }; + baseVideo.requestVideoFrameCallback(videoFrameCallback); + } else { + this.timeUpdateTimer_.tickEvery(/* seconds= */ 0.025); + } /** @private {shaka.util.Timer} */ this.pollTimer_ = new shaka.util.Timer(async () => {