diff options
author | Steejo <jieslater@gmail.com> | 2020-03-09 23:18:19 +0000 |
---|---|---|
committer | Steejo <jieslater@gmail.com> | 2020-03-09 23:18:19 +0000 |
commit | fd353225c27fa210a036b87a847336bf10957ed1 (patch) | |
tree | b6a8853d90d96dfe0c78487a4991cbe48ba2e7f3 /src | |
parent | 3c127afeb9e0059d1352ecb5b790633177a70cc4 (diff) | |
download | plyr-fd353225c27fa210a036b87a847336bf10957ed1.tar.lz plyr-fd353225c27fa210a036b87a847336bf10957ed1.tar.xz plyr-fd353225c27fa210a036b87a847336bf10957ed1.zip |
Ads plugin fixes to allow multiple VAST requests
Diffstat (limited to 'src')
-rw-r--r-- | src/js/plugins/ads.js | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/js/plugins/ads.js b/src/js/plugins/ads.js index 6b4fca10..79e6e5d9 100644 --- a/src/js/plugins/ads.js +++ b/src/js/plugins/ads.js @@ -172,6 +172,17 @@ class Ads { // We assume the adContainer is the video container of the plyr element that will house the ads this.elements.displayContainer = new google.ima.AdDisplayContainer(this.elements.container, this.player.media); + // Create ads loader + this.loader = new google.ima.AdsLoader(this.elements.displayContainer); + + // Listen and respond to ads loaded and error events + this.loader.addEventListener( + google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED, + event => this.onAdsManagerLoaded(event), + false, + ); + this.loader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, error => this.onAdError(error), false); + // Request video ads to be pre-loaded this.requestAds(); } @@ -183,17 +194,6 @@ class Ads { const { container } = this.player.elements; try { - // Create ads loader - this.loader = new google.ima.AdsLoader(this.elements.displayContainer); - - // Listen and respond to ads loaded and error events - this.loader.addEventListener( - google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED, - event => this.onAdsManagerLoaded(event), - false, - ); - this.loader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, error => this.onAdError(error), false); - // Request video ads const request = new google.ima.AdsRequest(); request.adTagUrl = this.tagUrl; @@ -369,7 +369,14 @@ class Ads { // TODO: So there is still this thing where a video should only be allowed to start // playing when the IMA SDK is ready or has failed - this.loadAds(); + if (player.ended){ + this.loadAds(); + } + else + { + // The SDK won't allow new ads to be called without receiving a contentComplete() + this.loader.contentComplete(); + } break; @@ -563,6 +570,8 @@ class Ads { this.on('loaded', resolve); this.player.debug.log(this.manager); }); + // Now that the manager has been destroyed set it to also be un-initialized + this.initialized = false; // Now request some new advertisements this.requestAds(); |