diff options
Diffstat (limited to 'dist/plyr.js')
-rw-r--r-- | dist/plyr.js | 117 |
1 files changed, 81 insertions, 36 deletions
diff --git a/dist/plyr.js b/dist/plyr.js index 3f4bbd62..5f6d36dc 100644 --- a/dist/plyr.js +++ b/dist/plyr.js @@ -437,7 +437,7 @@ typeof navigator === "object" && (function (global, factory) { }; var isPromise = function isPromise(input) { - return instanceOf$1(input, Promise); + return instanceOf$1(input, Promise) && isFunction$1(input.then); }; var isEmpty$1 = function isEmpty(input) { @@ -779,12 +779,14 @@ typeof navigator === "object" && (function (global, factory) { } // Element matches selector function matches$1(element, selector) { + var _Element = Element, + prototype = _Element.prototype; function match() { return Array.from(document.querySelectorAll(selector)).includes(this); } - var method = match; + var method = prototype.matches || prototype.webkitMatchesSelector || prototype.mozMatchesSelector || prototype.msMatchesSelector || match; return method.call(element, selector); } // Find all elements @@ -1056,6 +1058,19 @@ typeof navigator === "object" && (function (global, factory) { }).then(function () {}); } + /** + * Silence a Promise-like object. + * This is useful for avoiding non-harmful, but potentially confusing "uncaught + * play promise" rejection error messages. + * @param {Object} value An object that may or may not be `Promise`-like. + */ + + function silencePromise(value) { + if (is$1.promise(value)) { + value.then(null, function () {}); + } + } + function validateRatio(input) { if (!is$1.array(input) && (!is$1.string(input) || !input.includes(':'))) { return false; @@ -1232,7 +1247,7 @@ typeof navigator === "object" && (function (global, factory) { player.currentTime = currentTime; // Resume playing if (!paused) { - player.play(); + silencePromise(player.play()); } }); // Load new source @@ -4147,7 +4162,7 @@ typeof navigator === "object" && (function (global, factory) { if (browser.isIos && this.player.config.fullscreen.iosNative) { this.target.webkitExitFullscreen(); - this.player.play(); + silencePromise(this.player.play()); } else if (!Fullscreen.native || this.forceFallback) { this.toggleFallback(false); } else if (!this.prefix) { @@ -4194,7 +4209,7 @@ typeof navigator === "object" && (function (global, factory) { } var element = !this.prefix ? document.fullscreenElement : document["".concat(this.prefix).concat(this.property, "Element")]; - return element === this.target; + return element && element.shadowRoot ? element === this.target.getRootNode().host : element === this.target; } // Get target element }, { @@ -4572,7 +4587,7 @@ typeof navigator === "object" && (function (global, factory) { case 75: // Space and K key if (!repeat) { - player.togglePlay(); + silencePromise(player.togglePlay()); } break; @@ -4890,9 +4905,13 @@ typeof navigator === "object" && (function (global, factory) { if (player.ended) { _this.proxy(event, player.restart, 'restart'); - _this.proxy(event, player.play, 'play'); + _this.proxy(event, function () { + silencePromise(player.play()); + }, 'play'); } else { - _this.proxy(event, player.togglePlay, 'play'); + _this.proxy(event, function () { + silencePromise(player.togglePlay()); + }, 'play'); } }); } // Disable right click @@ -4990,7 +5009,9 @@ typeof navigator === "object" && (function (global, factory) { if (elements.buttons.play) { Array.from(elements.buttons.play).forEach(function (button) { - _this3.bind(button, 'click', player.togglePlay, 'play'); + _this3.bind(button, 'click', function () { + silencePromise(player.togglePlay()); + }, 'play'); }); } // Pause @@ -5087,7 +5108,7 @@ typeof navigator === "object" && (function (global, factory) { if (play && done) { seek.removeAttribute(attribute); - player.play(); + silencePromise(player.play()); } else if (!done && player.playing) { seek.setAttribute(attribute, ''); player.pause(); @@ -5722,6 +5743,9 @@ typeof navigator === "object" && (function (global, factory) { player.embed.setPlaybackRate(input).then(function () { speed = input; triggerEvent.call(player, player.media, 'ratechange'); + }).catch(function () { + // Cannot set Playback Rate, Video is probably not on Pro account + player.options.speed = [1]; }); } }); // Volume @@ -6461,6 +6485,8 @@ typeof navigator === "object" && (function (global, factory) { * mobile devices, this initialization is done as the result of a user action. */ value: function setupIMA() { + var _this4 = this; + // Create the container for our advertisements this.elements.container = createElement('div', { class: this.player.config.classNames.ads @@ -6473,7 +6499,16 @@ typeof navigator === "object" && (function (global, factory) { google.ima.settings.setDisableCustomPlaybackForIOS10Plus(this.player.config.playsinline); // We assume the adContainer is the video container of the plyr element that will house the ads - this.elements.displayContainer = new google.ima.AdDisplayContainer(this.elements.container, this.player.media); // Request video ads to be pre-loaded + this.elements.displayContainer = new google.ima.AdDisplayContainer(this.elements.container, this.player.media); // Create ads loader + + this.loader = new google.ima.AdsLoader(this.elements.displayContainer); // Listen and respond to ads loaded and error events + + this.loader.addEventListener(google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED, function (event) { + return _this4.onAdsManagerLoaded(event); + }, false); + this.loader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, function (error) { + return _this4.onAdError(error); + }, false); // Request video ads to be pre-loaded this.requestAds(); } @@ -6484,21 +6519,10 @@ typeof navigator === "object" && (function (global, factory) { }, { key: "requestAds", value: function requestAds() { - var _this4 = this; - var container = this.player.elements.container; try { - // Create ads loader - this.loader = new google.ima.AdsLoader(this.elements.displayContainer); // Listen and respond to ads loaded and error events - - this.loader.addEventListener(google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED, function (event) { - return _this4.onAdsManagerLoaded(event); - }, false); - this.loader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, function (error) { - return _this4.onAdError(error); - }, false); // Request video ads - + // Request video ads var request = new google.ima.AdsRequest(); request.adTagUrl = this.tagUrl; // Specify the linear and nonlinear slot sizes. This helps the SDK // to select the correct creative if multiple are returned @@ -6677,7 +6701,13 @@ typeof navigator === "object" && (function (global, factory) { // }; // TODO: So there is still this thing where a video should only be allowed to start // playing when the IMA SDK is ready or has failed - this.loadAds(); + if (this.player.ended) { + this.loadAds(); + } else { + // The SDK won't allow new ads to be called without receiving a contentComplete() + this.loader.contentComplete(); + } + break; case google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED: @@ -6813,7 +6843,7 @@ typeof navigator === "object" && (function (global, factory) { this.playing = false; // Play video - this.player.media.play(); + silencePromise(this.player.media.play()); } /** * Pause our video @@ -6870,7 +6900,9 @@ typeof navigator === "object" && (function (global, factory) { _this11.on('loaded', resolve); _this11.player.debug.log(_this11.manager); - }); // Now request some new advertisements + }); // Now that the manager has been destroyed set it to also be un-initialized + + _this11.initialized = false; // Now request some new advertisements _this11.requestAds(); }).catch(function () {}); @@ -7114,15 +7146,10 @@ typeof navigator === "object" && (function (global, factory) { if (is$1.empty(src)) { throw new Error('Missing previewThumbnails.src config attribute'); - } // If string, convert into single-element list - + } // Resolve promise - var urls = is$1.string(src) ? [src] : src; // Loop through each src URL. Download and process the VTT file, storing the resulting data in this.thumbnails - var promises = urls.map(function (u) { - return _this2.getThumbnail(u); - }); - Promise.all(promises).then(function () { + var sortAndResolve = function sortAndResolve() { // Sort smallest to biggest (e.g., [120p, 480p, 1080p]) _this2.thumbnails.sort(function (x, y) { return x.height - y.height; @@ -7131,7 +7158,25 @@ typeof navigator === "object" && (function (global, factory) { _this2.player.debug.log('Preview thumbnails', _this2.thumbnails); resolve(); - }); + }; // Via callback() + + + if (is$1.function(src)) { + src(function (thumbnails) { + _this2.thumbnails = thumbnails; + sortAndResolve(); + }); + } // VTT urls + else { + // If string, convert into single-element list + var urls = is$1.string(src) ? [src] : src; // Loop through each src URL. Download and process the VTT file, storing the resulting data in this.thumbnails + + var promises = urls.map(function (u) { + return _this2.getThumbnail(u); + }); // Resolve + + Promise.all(promises).then(sortAndResolve); + } }); } // Process individual VTT file @@ -8126,7 +8171,7 @@ typeof navigator === "object" && (function (global, factory) { if (this.isHTML5 && this.config.autoplay) { setTimeout(function () { - return _this.play(); + return silencePromise(_this.play()); }, 10); } // Seek time will be recorded (in listeners.js) so we can prevent hiding controls for a few seconds after seek @@ -8163,7 +8208,7 @@ typeof navigator === "object" && (function (global, factory) { this.ads.managerPromise.then(function () { return _this2.ads.play(); }).catch(function () { - return _this2.media.play(); + return silencePromise(_this2.media.play()); }); } // Return the promise (for HTML5) |