aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/js/defaults.js2
-rw-r--r--src/js/plugins/ads.js13
-rw-r--r--src/js/plyr.js13
3 files changed, 13 insertions, 15 deletions
diff --git a/src/js/defaults.js b/src/js/defaults.js
index 2a438d13..f7738afc 100644
--- a/src/js/defaults.js
+++ b/src/js/defaults.js
@@ -259,7 +259,7 @@ const defaults = {
// Ads
'adsloaded',
'adscontentpause',
- 'adsconentresume',
+ 'adscontentresume',
'adstarted',
'adsmidpoint',
'adscomplete',
diff --git a/src/js/plugins/ads.js b/src/js/plugins/ads.js
index 0faf0f2f..9318e01d 100644
--- a/src/js/plugins/ads.js
+++ b/src/js/plugins/ads.js
@@ -36,9 +36,8 @@ class Ads {
this.playing = false;
this.initialized = false;
this.blocked = false;
- this.enabled = utils.is.url(player.config.ads.tag);
- // Check if a tag URL is provided.
+ // Check if ads are enabled.
if (!this.enabled) {
return;
}
@@ -83,14 +82,12 @@ class Ads {
// thing doesn't resolve within our set time; we bail
this.startSafetyTimer(12000, 'ready()');
- // Setup a simple promise to resolve if the IMA loader is ready
- this.loaderPromise = new Promise(resolve => {
- this.on('ADS_LOADER_LOADED', () => resolve());
- });
-
// Setup a promise to resolve if the IMA manager is ready
- this.managerPromise = new Promise(resolve => {
+ this.managerPromise = new Promise((resolve, reject) => {
+ // The ad is pre-loaded and ready
this.on('ADS_MANAGER_LOADED', () => resolve());
+ // Ads failed
+ this.on('ERROR', () => reject());
});
// Clear the safety timer
diff --git a/src/js/plyr.js b/src/js/plyr.js
index 7f8ad18c..9b73423e 100644
--- a/src/js/plyr.js
+++ b/src/js/plyr.js
@@ -309,14 +309,15 @@ class Plyr {
* Play the media, or play the advertisement (if they are not blocked)
*/
play() {
- // TODO: Always return a promise?
if (this.ads.enabled && !this.ads.initialized && !this.ads.blocked) {
- this.ads.play();
- return null;
+ this.ads.managerPromise.then(() => {
+ this.ads.play();
+ }).catch(() => {
+ this.media.play();
+ });
+ } else {
+ this.media.play();
}
-
- // Return the promise (for HTML5)
- return this.media.play();
}
/**