diff options
Diffstat (limited to 'src/js/plugins/ads.js')
-rw-r--r-- | src/js/plugins/ads.js | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/js/plugins/ads.js b/src/js/plugins/ads.js index 3e8f0923..b9d9ac1c 100644 --- a/src/js/plugins/ads.js +++ b/src/js/plugins/ads.js @@ -206,21 +206,23 @@ class Ads { this.cuePoints = this.manager.getCuePoints(); // Add advertisement cue's within the time line if available - this.cuePoints.forEach(cuePoint => { - if (cuePoint !== 0 && cuePoint !== -1 && cuePoint < this.player.duration) { - const seekElement = this.player.elements.progress; - - if (seekElement) { - const cuePercentage = 100 / this.player.duration * cuePoint; - const cue = utils.createElement('span', { - class: this.player.config.classNames.cues, - }); - - cue.style.left = `${cuePercentage.toString()}%`; - seekElement.appendChild(cue); + if (!utils.is.empty(this.cuePoints)) { + this.cuePoints.forEach(cuePoint => { + if (cuePoint !== 0 && cuePoint !== -1 && cuePoint < this.player.duration) { + const seekElement = this.player.elements.progress; + + if (utils.is.element(seekElement)) { + const cuePercentage = 100 / this.player.duration * cuePoint; + const cue = utils.createElement('span', { + class: this.player.config.classNames.cues, + }); + + cue.style.left = `${cuePercentage.toString()}%`; + seekElement.appendChild(cue); + } } - } - }); + }); + } // Get skippable state // TODO: Skip button @@ -385,6 +387,10 @@ class Ads { this.player.on('seeked', () => { const seekedTime = this.player.currentTime; + if (utils.is.empty(this.cuePoints)) { + return; + } + this.cuePoints.forEach((cuePoint, index) => { if (time < cuePoint && cuePoint < seekedTime) { this.manager.discardAdBreak(); @@ -396,7 +402,9 @@ class Ads { // Listen to the resizing of the window. And resize ad accordingly // TODO: eventually implement ResizeObserver window.addEventListener('resize', () => { - this.manager.resize(container.offsetWidth, container.offsetHeight, google.ima.ViewMode.NORMAL); + if (this.manager) { + this.manager.resize(container.offsetWidth, container.offsetHeight, google.ima.ViewMode.NORMAL); + } }); } |