diff options
author | Sam Potts <sam@potts.es> | 2018-05-08 22:22:43 +1000 |
---|---|---|
committer | Sam Potts <sam@potts.es> | 2018-05-08 22:22:43 +1000 |
commit | 34401de3d03e61eb7d1a04f6f0b7599e7ce9cd93 (patch) | |
tree | f8f46e1f38bdfb28d8ccc146a4d014ca1ca05a31 /src/js/plugins | |
parent | 403df36af6813acf762e2b85bae6b1584b781c59 (diff) | |
parent | f687b81b70a73835f0190fbfa17a0fbbfcd28b7a (diff) | |
download | plyr-34401de3d03e61eb7d1a04f6f0b7599e7ce9cd93.tar.lz plyr-34401de3d03e61eb7d1a04f6f0b7599e7ce9cd93.tar.xz plyr-34401de3d03e61eb7d1a04f6f0b7599e7ce9cd93.zip |
Merge branch 'master' into develop
Diffstat (limited to 'src/js/plugins')
-rw-r--r-- | src/js/plugins/ads.js | 14 | ||||
-rw-r--r-- | src/js/plugins/vimeo.js | 35 | ||||
-rw-r--r-- | src/js/plugins/youtube.js | 9 |
3 files changed, 45 insertions, 13 deletions
diff --git a/src/js/plugins/ads.js b/src/js/plugins/ads.js index b9d9ac1c..0246e221 100644 --- a/src/js/plugins/ads.js +++ b/src/js/plugins/ads.js @@ -6,8 +6,8 @@ /* global google */ -import utils from '../utils'; import i18n from '../i18n'; +import utils from '../utils'; class Ads { /** @@ -18,7 +18,6 @@ class Ads { constructor(player) { this.player = player; this.publisherId = player.config.ads.publisherId; - this.enabled = player.isHTML5 && player.isVideo && player.config.ads.enabled && utils.is.string(this.publisherId) && this.publisherId.length; this.playing = false; this.initialized = false; this.elements = { @@ -44,6 +43,10 @@ class Ads { this.load(); } + get enabled() { + return this.player.isVideo && this.player.config.ads.enabled && !utils.is.empty(this.publisherId); + } + /** * Load the IMA SDK */ @@ -52,7 +55,7 @@ class Ads { // Check if the Google IMA3 SDK is loaded or load it ourselves if (!utils.is.object(window.google) || !utils.is.object(window.google.ima)) { utils - .loadScript(this.player.config.urls.googleIMA.api) + .loadScript(this.player.config.urls.googleIMA.sdk) .then(() => { this.ready(); }) @@ -160,6 +163,9 @@ class Ads { // We only overlay ads as we only support video. request.forceNonLinearFullSlot = false; + // Mute based on current state + request.setAdWillPlayMuted(!this.player.muted); + this.loader.requestAds(request); } catch (e) { this.onAdError(e); @@ -226,7 +232,7 @@ class Ads { // Get skippable state // TODO: Skip button - // this.manager.getAdSkippableState(); + // this.player.debug.warn(this.manager.getAdSkippableState()); // Set volume to match player this.manager.setVolume(this.player.volume); diff --git a/src/js/plugins/vimeo.js b/src/js/plugins/vimeo.js index 24003d3f..0ceb89e5 100644 --- a/src/js/plugins/vimeo.js +++ b/src/js/plugins/vimeo.js @@ -2,10 +2,10 @@ // Vimeo plugin // ========================================================================== -import utils from './../utils'; import captions from './../captions'; import controls from './../controls'; import ui from './../ui'; +import utils from './../utils'; const vimeo = { setup() { @@ -18,7 +18,7 @@ const vimeo = { // Load the API if not already if (!utils.is.object(window.Vimeo)) { utils - .loadScript(this.config.urls.vimeo.api) + .loadScript(this.config.urls.vimeo.sdk) .then(() => { vimeo.ready.call(this); }) @@ -53,6 +53,7 @@ const vimeo = { const options = { loop: player.config.loop.active, autoplay: player.autoplay, + // muted: player.muted, byline: false, portrait: false, title: false, @@ -68,27 +69,49 @@ const vimeo = { // Get from <div> if needed if (utils.is.empty(source)) { - source = player.media.getAttribute(this.config.attributes.embed.id); + source = player.media.getAttribute(player.config.attributes.embed.id); } const id = utils.parseVimeoId(source); // Build an iframe const iframe = utils.createElement('iframe'); - const src = `https://player.vimeo.com/video/${id}?${params}`; + const src = utils.format(player.config.urls.vimeo.iframe, id, params); iframe.setAttribute('src', src); iframe.setAttribute('allowfullscreen', ''); iframe.setAttribute('allowtransparency', ''); iframe.setAttribute('allow', 'autoplay'); // Inject the package - const wrapper = utils.createElement('div'); + const wrapper = utils.createElement('div', { class: player.config.classNames.embedContainer }); wrapper.appendChild(iframe); player.media = utils.replaceElement(wrapper, player.media); + // Get poster image + utils.fetch(utils.format(player.config.urls.vimeo.api, id), 'json').then(response => { + if (utils.is.empty(response)) { + return; + } + + // Get the URL for thumbnail + const url = new URL(response[0].thumbnail_large); + + // Get original image + url.pathname = `${url.pathname.split('_')[0]}.jpg`; + + // Set attribute + player.media.setAttribute('poster', url.href); + + // Update + ui.setPoster.call(player); + }); + // Setup instance // https://github.com/vimeo/player.js - player.embed = new window.Vimeo.Player(iframe); + player.embed = new window.Vimeo.Player(iframe, { + autopause: player.config.autopause, + muted: player.muted, + }); player.media.paused = true; player.media.currentTime = 0; diff --git a/src/js/plugins/youtube.js b/src/js/plugins/youtube.js index 12bc2b11..4fde9319 100644 --- a/src/js/plugins/youtube.js +++ b/src/js/plugins/youtube.js @@ -2,9 +2,9 @@ // YouTube plugin // ========================================================================== -import utils from './../utils'; import controls from './../controls'; import ui from './../ui'; +import utils from './../utils'; // Standardise YouTube quality unit function mapQualityUnit(input) { @@ -77,7 +77,7 @@ const youtube = { youtube.ready.call(this); } else { // Load the API - utils.loadScript(this.config.urls.youtube.api).catch(error => { + utils.loadScript(this.config.urls.youtube.sdk).catch(error => { this.debug.warn('YouTube API failed to load', error); }); @@ -117,7 +117,7 @@ const youtube = { // Or via Google API const key = this.config.keys.google; if (utils.is.string(key) && !utils.is.empty(key)) { - const url = `https://www.googleapis.com/youtube/v3/videos?id=${videoId}&key=${key}&fields=items(snippet(title))&part=snippet`; + const url = utils.format(this.config.urls.youtube.api, videoId, key); utils .fetch(url) @@ -161,6 +161,9 @@ const youtube = { const container = utils.createElement('div', { id }); player.media = utils.replaceElement(container, player.media); + // Set poster image + player.media.setAttribute('poster', utils.format(player.config.urls.youtube.poster, videoId)); + // Setup instance // https://developers.google.com/youtube/iframe_api_reference player.embed = new window.YT.Player(id, { |