aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/plugins/ads.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/plugins/ads.js')
-rw-r--r--src/js/plugins/ads.js56
1 files changed, 31 insertions, 25 deletions
diff --git a/src/js/plugins/ads.js b/src/js/plugins/ads.js
index c643c5dd..6efd3295 100644
--- a/src/js/plugins/ads.js
+++ b/src/js/plugins/ads.js
@@ -136,6 +136,7 @@ class Ads {
this.elements.container = createElement('div', {
class: this.player.config.classNames.ads,
});
+
this.player.elements.container.appendChild(this.elements.container);
// So we can run VPAID2
@@ -144,9 +145,11 @@ class Ads {
// Set language
google.ima.settings.setLocale(this.player.config.ads.language);
- // 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);
+ // Set playback for iOS10+
+ google.ima.settings.setDisableCustomPlaybackForIOS10Plus(this.player.config.playsinline);
+
+ // 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);
// Request video ads to be pre-loaded
this.requestAds();
@@ -237,6 +240,23 @@ class Ads {
// Get the cue points for any mid-rolls by filtering out the pre- and post-roll
this.cuePoints = this.manager.getCuePoints();
+ // Set volume to match player
+ this.manager.setVolume(this.player.volume);
+
+ // Add listeners to the required events
+ // Advertisement error events
+ this.manager.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, error => this.onAdError(error));
+
+ // Advertisement regular events
+ Object.keys(google.ima.AdEvent.Type).forEach(type => {
+ this.manager.addEventListener(google.ima.AdEvent.Type[type], event => this.onAdEvent(event));
+ });
+
+ // Resolve our adsManager
+ this.trigger('loaded');
+ }
+
+ addCuePoints() {
// Add advertisement cue's within the time line if available
if (!is.empty(this.cuePoints)) {
this.cuePoints.forEach(cuePoint => {
@@ -255,21 +275,6 @@ class Ads {
}
});
}
-
- // Set volume to match player
- this.manager.setVolume(this.player.volume);
-
- // Add listeners to the required events
- // Advertisement error events
- this.manager.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, error => this.onAdError(error));
-
- // Advertisement regular events
- Object.keys(google.ima.AdEvent.Type).forEach(type => {
- this.manager.addEventListener(google.ima.AdEvent.Type[type], event => this.onAdEvent(event));
- });
-
- // Resolve our adsManager
- this.trigger('loaded');
}
/**
@@ -409,7 +414,10 @@ class Ads {
const { container } = this.player.elements;
let time;
- // Add listeners to the required events
+ this.player.on('canplay', () => {
+ this.addCuePoints();
+ });
+
this.player.on('ended', () => {
this.loader.contentComplete();
});
@@ -488,10 +496,8 @@ class Ads {
// Ad is stopped
this.playing = false;
- // Play our video
- if (this.player.currentTime < this.player.duration) {
- this.player.play();
- }
+ // Play video
+ this.player.media.play();
}
/**
@@ -501,11 +507,11 @@ class Ads {
// Show the advertisement container
this.elements.container.style.zIndex = 3;
- // Ad is playing.
+ // Ad is playing
this.playing = true;
// Pause our video.
- this.player.pause();
+ this.player.media.pause();
}
/**