Fix loading/playing of the ads when there is no valid ads.tagUrl

This commit is contained in:
ferdiemmen 2018-01-17 08:31:36 +01:00
parent ec73d34bd3
commit 8348f79742
4 changed files with 20 additions and 32 deletions

2
dist/plyr.js vendored

File diff suppressed because one or more lines are too long

2
dist/plyr.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -21,8 +21,8 @@ const getStartEvents = () => {
class Ads { class Ads {
constructor(player) { constructor(player) {
this.player = player; this.player = player;
this.isPlaying = false; this.playing = false;
this.isInitialized = false; this.initialized = false;
// Check if a tag URL is provided. // Check if a tag URL is provided.
if (!utils.is.url(player.config.ads.tagUrl)) { if (!utils.is.url(player.config.ads.tagUrl)) {
@ -39,22 +39,6 @@ class Ads {
} }
} }
set playing(bool = false) {
this.isPlaying = bool;
}
get playing() {
return this.isPlaying;
}
set initialized(bool = false) {
this.isInitialized = bool;
}
get initialized() {
return this.isInitialized;
}
ready() { ready() {
this.time = Date.now(); this.time = Date.now();
this.startEvents = getStartEvents(); this.startEvents = getStartEvents();
@ -298,10 +282,7 @@ class Ads {
onAdError(adErrorEvent) { onAdError(adErrorEvent) {
this.cancel(); this.cancel();
this.player.debug.log(`[${(Date.now() - this.time) / 1000}s][IMA SDK] ERROR |`, adErrorEvent);
if (this.player.debug) {
throw new Error(adErrorEvent);
}
} }
setupAdDisplayContainer() { setupAdDisplayContainer() {

View File

@ -276,8 +276,10 @@ class Plyr {
} }
// Setup ads if provided // Setup ads if provided
if (utils.is.url(this.config.ads.tagUrl)) {
this.ads = new Ads(this); this.ads = new Ads(this);
} }
}
// --------------------------------------- // ---------------------------------------
// API // API
@ -306,17 +308,22 @@ class Plyr {
} }
/** /**
* Play the media * Play the media, or play the advertisement
*/ */
play() { play() {
if (this.ads) { if (utils.is.url(this.config.ads.tagUrl)) {
if (this.ads.playing) {
return;
}
if (!this.ads.initialized) {
this.ads.play(); this.ads.play();
} }
if (!this.ads.playing) { if (!this.ads.playing) {
return this.media.play(); this.media.play();
} }
} }
this.media.play();
}
/** /**
* Pause the media * Pause the media