diff options
author | Sam Potts <sam@potts.es> | 2019-01-26 17:19:58 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-26 17:19:58 +1100 |
commit | a84fc396e8a53fd595c204deff227104b0255865 (patch) | |
tree | 9f9e927b6ecbeba39c2a6dfc1b51b2d750b352db /src/js | |
parent | 052e426810d504a01beb05c8bb34f83e190a0679 (diff) | |
parent | 8b57104f8396c4110f217c854099243d8d04ae20 (diff) | |
download | plyr-a84fc396e8a53fd595c204deff227104b0255865.tar.lz plyr-a84fc396e8a53fd595c204deff227104b0255865.tar.xz plyr-a84fc396e8a53fd595c204deff227104b0255865.zip |
Merge branch 'develop' into issues/1316-allow-to-customize-vimeo-url-params
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/config/defaults.js | 4 | ||||
-rw-r--r-- | src/js/plugins/ads.js | 29 | ||||
-rw-r--r-- | src/js/plugins/previewThumbnails.js | 19 | ||||
-rw-r--r-- | src/js/plyr.js | 2 | ||||
-rw-r--r-- | src/js/plyr.polyfilled.js | 2 |
5 files changed, 43 insertions, 13 deletions
diff --git a/src/js/config/defaults.js b/src/js/config/defaults.js index 1891074d..650bcd2a 100644 --- a/src/js/config/defaults.js +++ b/src/js/config/defaults.js @@ -60,7 +60,7 @@ const defaults = { // Sprite (for icons) loadSprite: true, iconPrefix: 'plyr', - iconUrl: 'https://cdn.plyr.io/3.4.7/plyr.svg', + iconUrl: 'https://cdn.plyr.io/3.4.8/plyr.svg', // Blank video (used to prevent errors on source change) blankVideo: 'https://cdn.plyr.io/static/blank.mp4', @@ -404,6 +404,7 @@ const defaults = { ads: { enabled: false, publisherId: '', + tagUrl: '', }, // YouTube nocookies mode @@ -412,6 +413,7 @@ const defaults = { // Preview Thumbnails plugin previewThumbnails: { enabled: false, + src: '', }, // Vimeo plugin diff --git a/src/js/plugins/ads.js b/src/js/plugins/ads.js index 375fdc13..c643c5dd 100644 --- a/src/js/plugins/ads.js +++ b/src/js/plugins/ads.js @@ -22,7 +22,7 @@ class Ads { */ constructor(player) { this.player = player; - this.publisherId = player.config.ads.publisherId; + this.config = player.config.ads; this.playing = false; this.initialized = false; this.elements = { @@ -49,8 +49,13 @@ class Ads { } get enabled() { + const { config } = this; + return ( - this.player.isHTML5 && this.player.isVideo && this.player.config.ads.enabled && !is.empty(this.publisherId) + this.player.isHTML5 && + this.player.isVideo && + config.enabled && + (!is.empty(config.publisherId) || is.url(config.tagUrl)) ); } @@ -95,8 +100,14 @@ class Ads { this.setupIMA(); } - // Build the default tag URL + // Build the tag URL get tagUrl() { + const { config } = this; + + if (is.url(config.tagUrl)) { + return config.tagUrl; + } + const params = { AV_PUBLISHERID: '58c25bb0073ef448b1087ad6', AV_CHANNELID: '5a0458dc28a06145e4519d21', @@ -233,7 +244,7 @@ class Ads { const seekElement = this.player.elements.progress; if (is.element(seekElement)) { - const cuePercentage = 100 / this.player.duration * cuePoint; + const cuePercentage = (100 / this.player.duration) * cuePoint; const cue = createElement('span', { class: this.player.config.classNames.cues, }); @@ -273,6 +284,7 @@ class Ads { // Retrieve the ad from the event. Some events (e.g. ALL_ADS_COMPLETED) // don't have ad object associated const ad = event.getAd(); + const adData = event.getAdData(); // Proxy event const dispatchEvent = type => { @@ -368,6 +380,12 @@ class Ads { dispatchEvent(event.type); break; + case google.ima.AdEvent.Type.LOG: + if (adData.adError) { + this.player.debug.warn(`Non-fatal ad error: ${adData.adError.getMessage()}`); + } + break; + default: break; } @@ -396,9 +414,8 @@ class Ads { this.loader.contentComplete(); }); - this.player.on('seeking', () => { + this.player.on('timeupdate', () => { time = this.player.currentTime; - return time; }); this.player.on('seeked', () => { diff --git a/src/js/plugins/previewThumbnails.js b/src/js/plugins/previewThumbnails.js index 053875c7..3832be5c 100644 --- a/src/js/plugins/previewThumbnails.js +++ b/src/js/plugins/previewThumbnails.js @@ -109,20 +109,22 @@ class PreviewThumbnails { // Download VTT files and parse them getThumbnails() { return new Promise(resolve => { - if (!this.player.config.previewThumbnails.src) { + const { src } = this.player.config.previewThumbnails; + + if (is.empty(src)) { throw new Error('Missing previewThumbnails.src config attribute'); } - // previewThumbnails.src can be string or list. If string, convert into single-element list - const { src } = this.player.config.previewThumbnails; + // If string, convert into single-element list const urls = is.string(src) ? [src] : src; - // Loop through each src url. Download and process the VTT file, storing the resulting data in this.thumbnails + // Loop through each src URL. Download and process the VTT file, storing the resulting data in this.thumbnails const promises = urls.map(u => this.getThumbnail(u)); Promise.all(promises).then(() => { // Sort smallest to biggest (e.g., [120p, 480p, 1080p]) this.thumbnails.sort((x, y) => x.height - y.height); + this.player.debug.log('Preview thumbnails', this.thumbnails); resolve(); @@ -301,11 +303,20 @@ class PreviewThumbnails { } // Find the desired thumbnail index + // TODO: Handle a video longer than the thumbs where thumbNum is null const thumbNum = this.thumbnails[0].frames.findIndex( frame => this.seekTime >= frame.startTime && this.seekTime <= frame.endTime, ); + const hasThumb = thumbNum >= 0; let qualityIndex = 0; + this.toggleThumbContainer(hasThumb); + + // No matching thumb found + if (!hasThumb) { + return; + } + // Check to see if we've already downloaded higher quality versions of this image this.thumbnails.forEach((thumbnail, index) => { if (this.loadedImages.includes(thumbnail.frames[thumbNum].text)) { diff --git a/src/js/plyr.js b/src/js/plyr.js index 1059ce05..674ffb3c 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -1,6 +1,6 @@ // ========================================================================== // Plyr -// plyr.js v3.4.7 +// plyr.js v3.4.8 // https://github.com/sampotts/plyr // License: The MIT License (MIT) // ========================================================================== diff --git a/src/js/plyr.polyfilled.js b/src/js/plyr.polyfilled.js index ac6d1c28..42207a1e 100644 --- a/src/js/plyr.polyfilled.js +++ b/src/js/plyr.polyfilled.js @@ -1,6 +1,6 @@ // ========================================================================== // Plyr Polyfilled Build -// plyr.js v3.4.7 +// plyr.js v3.4.8 // https://github.com/sampotts/plyr // License: The MIT License (MIT) // ========================================================================== |