diff --git a/lib/ads/client_side_ad_manager.js b/lib/ads/client_side_ad_manager.js index a608f927a0..591fecae81 100644 --- a/lib/ads/client_side_ad_manager.js +++ b/lib/ads/client_side_ad_manager.js @@ -33,6 +33,9 @@ shaka.ads.ClientSideAdManager = class { /** @private {HTMLMediaElement} */ this.video_ = video; + /** @private {boolean} */ + this.videoPlayed_ = false; + /** @private {ResizeObserver} */ this.resizeObserver_ = null; @@ -82,6 +85,10 @@ shaka.ads.ClientSideAdManager = class { this.eventManager_.listen(this.video_, 'ended', () => { this.adsLoader_.contentComplete(); }); + + this.eventManager_.listenOnce(this.video_, 'play', () => { + this.videoPlayed_ = true; + }); } /** @@ -219,9 +226,14 @@ shaka.ads.ClientSideAdManager = class { // seen the ads actually play until requestAds() is called. // Note: We listen for a play event to avoid autoplay issues that might // crash IMA. - this.eventManager_.listenOnce(this.video_, 'play', () => { + if (this.videoPlayed_) { this.imaAdsManager_.start(); - }); + } else { + this.eventManager_.listenOnce(this.video_, 'play', () => { + this.videoPlayed_ = true; + this.imaAdsManager_.start(); + }); + } } catch (adError) { // If there was a problem with the VAST response, // we we won't be getting an ad. Hide ad UI if we showed it already