From ac6e3dba5a7ed25a01097a9bd165160652febba9 Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Mon, 3 Jun 2019 00:28:09 +1000 Subject: Fix for thumbnails in demo for audio --- src/js/plugins/previewThumbnails.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/js/plugins') diff --git a/src/js/plugins/previewThumbnails.js b/src/js/plugins/previewThumbnails.js index b4714117..67367b95 100644 --- a/src/js/plugins/previewThumbnails.js +++ b/src/js/plugins/previewThumbnails.js @@ -101,6 +101,10 @@ class PreviewThumbnails { } this.getThumbnails().then(() => { + if (!this.enabled) { + return; + } + // Render DOM elements this.render(); -- cgit v1.2.3 From 8fc6c2ba526bf1ef8cdb9476f1644089281ce60d Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Fri, 21 Jun 2019 00:19:37 +1000 Subject: File rename and clean up --- src/js/plugins/ads.js | 2 +- src/js/plugins/preview-thumbnails.js | 652 ++++++++++++++++++++++++++++++++++ src/js/plugins/previewThumbnails.js | 653 ----------------------------------- src/js/plugins/vimeo.js | 2 +- src/js/plugins/youtube.js | 4 +- 5 files changed, 656 insertions(+), 657 deletions(-) create mode 100644 src/js/plugins/preview-thumbnails.js delete mode 100644 src/js/plugins/previewThumbnails.js (limited to 'src/js/plugins') diff --git a/src/js/plugins/ads.js b/src/js/plugins/ads.js index e6fab967..db55e499 100644 --- a/src/js/plugins/ads.js +++ b/src/js/plugins/ads.js @@ -10,7 +10,7 @@ import { createElement } from '../utils/elements'; import { triggerEvent } from '../utils/events'; import i18n from '../utils/i18n'; import is from '../utils/is'; -import loadScript from '../utils/loadScript'; +import loadScript from '../utils/load-script'; import { formatTime } from '../utils/time'; import { buildUrlParams } from '../utils/urls'; diff --git a/src/js/plugins/preview-thumbnails.js b/src/js/plugins/preview-thumbnails.js new file mode 100644 index 00000000..61021d64 --- /dev/null +++ b/src/js/plugins/preview-thumbnails.js @@ -0,0 +1,652 @@ +import { createElement } from '../utils/elements'; +import { once } from '../utils/events'; +import fetch from '../utils/fetch'; +import is from '../utils/is'; +import { formatTime } from '../utils/time'; + +// Arg: vttDataString example: "WEBVTT\n\n1\n00:00:05.000 --> 00:00:10.000\n1080p-00001.jpg" +const parseVtt = vttDataString => { + const processedList = []; + const frames = vttDataString.split(/\r\n\r\n|\n\n|\r\r/); + + frames.forEach(frame => { + const result = {}; + const lines = frame.split(/\r\n|\n|\r/); + + lines.forEach(line => { + if (!is.number(result.startTime)) { + // The line with start and end times on it is the first line of interest + const matchTimes = line.match( + /([0-9]{2})?:?([0-9]{2}):([0-9]{2}).([0-9]{2,3})( ?--> ?)([0-9]{2})?:?([0-9]{2}):([0-9]{2}).([0-9]{2,3})/, + ); // Note that this currently ignores caption formatting directives that are optionally on the end of this line - fine for non-captions VTT + + if (matchTimes) { + result.startTime = + Number(matchTimes[1] || 0) * 60 * 60 + + Number(matchTimes[2]) * 60 + + Number(matchTimes[3]) + + Number(`0.${matchTimes[4]}`); + result.endTime = + Number(matchTimes[6] || 0) * 60 * 60 + + Number(matchTimes[7]) * 60 + + Number(matchTimes[8]) + + Number(`0.${matchTimes[9]}`); + } + } else if (!is.empty(line.trim()) && is.empty(result.text)) { + // If we already have the startTime, then we're definitely up to the text line(s) + const lineSplit = line.trim().split('#xywh='); + [result.text] = lineSplit; + + // If there's content in lineSplit[1], then we have sprites. If not, then it's just one frame per image + if (lineSplit[1]) { + [result.x, result.y, result.w, result.h] = lineSplit[1].split(','); + } + } + }); + + if (result.text) { + processedList.push(result); + } + }); + + return processedList; +}; + +/** + * Preview thumbnails for seek hover and scrubbing + * Seeking: Hover over the seek bar (desktop only): shows a small preview container above the seek bar + * Scrubbing: Click and drag the seek bar (desktop and mobile): shows the preview image over the entire video, as if the video is scrubbing at very high speed + * + * Notes: + * - Thumbs are set via JS settings on Plyr init, not HTML5 'track' property. Using the track property would be a bit gross, because it doesn't support custom 'kinds'. kind=metadata might be used for something else, and we want to allow multiple thumbnails tracks. Tracks must have a unique combination of 'kind' and 'label'. We would have to do something like kind=metadata,label=thumbnails1 / kind=metadata,label=thumbnails2. Square peg, round hole + * - VTT info: the image URL is relative to the VTT, not the current document. But if the url starts with a slash, it will naturally be relative to the current domain. https://support.jwplayer.com/articles/how-to-add-preview-thumbnails + * - This implementation uses multiple separate img elements. Other implementations use background-image on one element. This would be nice and simple, but Firefox and Safari have flickering issues with replacing backgrounds of larger images. It seems that YouTube perhaps only avoids this because they don't have the option for high-res previews (even the fullscreen ones, when mousedown/seeking). Images appear over the top of each other, and previous ones are discarded once the new ones have been rendered + */ + +class PreviewThumbnails { + /** + * PreviewThumbnails constructor. + * @param {Plyr} player + * @return {PreviewThumbnails} + */ + constructor(player) { + this.player = player; + this.thumbnails = []; + this.loaded = false; + this.lastMouseMoveTime = Date.now(); + this.mouseDown = false; + this.loadedImages = []; + + this.elements = { + thumb: {}, + scrubbing: {}, + }; + + this.load(); + } + + get enabled() { + return this.player.isHTML5 && this.player.isVideo && this.player.config.previewThumbnails.enabled; + } + + load() { + // Togglethe regular seek tooltip + if (this.player.elements.display.seekTooltip) { + this.player.elements.display.seekTooltip.hidden = this.enabled; + } + + if (!this.enabled) { + return; + } + + this.getThumbnails().then(() => { + if (!this.enabled) { + return; + } + + // Render DOM elements + this.render(); + + // Check to see if thumb container size was specified manually in CSS + this.determineContainerAutoSizing(); + + this.loaded = true; + }); + } + + // Download VTT files and parse them + getThumbnails() { + return new Promise(resolve => { + const { src } = this.player.config.previewThumbnails; + + if (is.empty(src)) { + throw new Error('Missing previewThumbnails.src config attribute'); + } + + // 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 + 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(); + }); + }); + } + + // Process individual VTT file + getThumbnail(url) { + return new Promise(resolve => { + fetch(url).then(response => { + const thumbnail = { + frames: parseVtt(response), + height: null, + urlPrefix: '', + }; + + // If the URLs don't start with '/', then we need to set their relative path to be the location of the VTT file + // If the URLs do start with '/', then they obviously don't need a prefix, so it will remain blank + // If the thumbnail URLs start with with none of '/', 'http://' or 'https://', then we need to set their relative path to be the location of the VTT file + if ( + !thumbnail.frames[0].text.startsWith('/') && + !thumbnail.frames[0].text.startsWith('http://') && + !thumbnail.frames[0].text.startsWith('https://') + ) { + thumbnail.urlPrefix = url.substring(0, url.lastIndexOf('/') + 1); + } + + // Download the first frame, so that we can determine/set the height of this thumbnailsDef + const tempImage = new Image(); + + tempImage.onload = () => { + thumbnail.height = tempImage.naturalHeight; + thumbnail.width = tempImage.naturalWidth; + + this.thumbnails.push(thumbnail); + + resolve(); + }; + + tempImage.src = thumbnail.urlPrefix + thumbnail.frames[0].text; + }); + }); + } + + startMove(event) { + if (!this.loaded) { + return; + } + + if (!is.event(event) || !['touchmove', 'mousemove'].includes(event.type)) { + return; + } + + // Wait until media has a duration + if (!this.player.media.duration) { + return; + } + + if (event.type === 'touchmove') { + // Calculate seek hover position as approx video seconds + this.seekTime = this.player.media.duration * (this.player.elements.inputs.seek.value / 100); + } else { + // Calculate seek hover position as approx video seconds + const clientRect = this.player.elements.progress.getBoundingClientRect(); + const percentage = (100 / clientRect.width) * (event.pageX - clientRect.left); + this.seekTime = this.player.media.duration * (percentage / 100); + + if (this.seekTime < 0) { + // The mousemove fires for 10+px out to the left + this.seekTime = 0; + } + + if (this.seekTime > this.player.media.duration - 1) { + // Took 1 second off the duration for safety, because different players can disagree on the real duration of a video + this.seekTime = this.player.media.duration - 1; + } + + this.mousePosX = event.pageX; + + // Set time text inside image container + this.elements.thumb.time.innerText = formatTime(this.seekTime); + } + + // Download and show image + this.showImageAtCurrentTime(); + } + + endMove() { + this.toggleThumbContainer(false, true); + } + + startScrubbing(event) { + // Only act on left mouse button (0), or touch device (event.button is false) + if (event.button === false || event.button === 0) { + this.mouseDown = true; + + // Wait until media has a duration + if (this.player.media.duration) { + this.toggleScrubbingContainer(true); + this.toggleThumbContainer(false, true); + + // Download and show image + this.showImageAtCurrentTime(); + } + } + } + + endScrubbing() { + this.mouseDown = false; + + // Hide scrubbing preview. But wait until the video has successfully seeked before hiding the scrubbing preview + if (Math.ceil(this.lastTime) === Math.ceil(this.player.media.currentTime)) { + // The video was already seeked/loaded at the chosen time - hide immediately + this.toggleScrubbingContainer(false); + } else { + // The video hasn't seeked yet. Wait for that + once.call(this.player, this.player.media, 'timeupdate', () => { + // Re-check mousedown - we might have already started scrubbing again + if (!this.mouseDown) { + this.toggleScrubbingContainer(false); + } + }); + } + } + + /** + * Setup hooks for Plyr and window events + */ + listeners() { + // Hide thumbnail preview - on mouse click, mouse leave (in listeners.js for now), and video play/seek. All four are required, e.g., for buffering + this.player.on('play', () => { + this.toggleThumbContainer(false, true); + }); + + this.player.on('seeked', () => { + this.toggleThumbContainer(false); + }); + + this.player.on('timeupdate', () => { + this.lastTime = this.player.media.currentTime; + }); + } + + /** + * Create HTML elements for image containers + */ + render() { + // Create HTML element: plyr__preview-thumbnail-container + this.elements.thumb.container = createElement('div', { + class: this.player.config.classNames.previewThumbnails.thumbContainer, + }); + + // Wrapper for the image for styling + this.elements.thumb.imageContainer = createElement('div', { + class: this.player.config.classNames.previewThumbnails.imageContainer, + }); + this.elements.thumb.container.appendChild(this.elements.thumb.imageContainer); + + // Create HTML element, parent+span: time text (e.g., 01:32:00) + const timeContainer = createElement('div', { + class: this.player.config.classNames.previewThumbnails.timeContainer, + }); + + this.elements.thumb.time = createElement('span', {}, '00:00'); + timeContainer.appendChild(this.elements.thumb.time); + + this.elements.thumb.container.appendChild(timeContainer); + + // Inject the whole thumb + if (is.element(this.player.elements.progress)) { + this.player.elements.progress.appendChild(this.elements.thumb.container); + } + + // Create HTML element: plyr__preview-scrubbing-container + this.elements.scrubbing.container = createElement('div', { + class: this.player.config.classNames.previewThumbnails.scrubbingContainer, + }); + + this.player.elements.wrapper.appendChild(this.elements.scrubbing.container); + } + + showImageAtCurrentTime() { + if (this.mouseDown) { + this.setScrubbingContainerSize(); + } else { + this.setThumbContainerSizeAndPos(); + } + + // 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; + + // Show the thumb container if we're not scrubbing + if (!this.mouseDown) { + 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)) { + qualityIndex = index; + } + }); + + // Only proceed if either thumbnum or thumbfilename has changed + if (thumbNum !== this.showingThumb) { + this.showingThumb = thumbNum; + this.loadImage(qualityIndex); + } + } + + // Show the image that's currently specified in this.showingThumb + loadImage(qualityIndex = 0) { + const thumbNum = this.showingThumb; + const thumbnail = this.thumbnails[qualityIndex]; + const { urlPrefix } = thumbnail; + const frame = thumbnail.frames[thumbNum]; + const thumbFilename = thumbnail.frames[thumbNum].text; + const thumbUrl = urlPrefix + thumbFilename; + + if (!this.currentImageElement || this.currentImageElement.dataset.filename !== thumbFilename) { + // If we're already loading a previous image, remove its onload handler - we don't want it to load after this one + // Only do this if not using sprites. Without sprites we really want to show as many images as possible, as a best-effort + if (this.loadingImage && this.usingSprites) { + this.loadingImage.onload = null; + } + + // We're building and adding a new image. In other implementations of similar functionality (YouTube), background image + // is instead used. But this causes issues with larger images in Firefox and Safari - switching between background + // images causes a flicker. Putting a new image over the top does not + const previewImage = new Image(); + previewImage.src = thumbUrl; + previewImage.dataset.index = thumbNum; + previewImage.dataset.filename = thumbFilename; + this.showingThumbFilename = thumbFilename; + + this.player.debug.log(`Loading image: ${thumbUrl}`); + + // For some reason, passing the named function directly causes it to execute immediately. So I've wrapped it in an anonymous function... + previewImage.onload = () => + this.showImage(previewImage, frame, qualityIndex, thumbNum, thumbFilename, true); + this.loadingImage = previewImage; + this.removeOldImages(previewImage); + } else { + // Update the existing image + this.showImage(this.currentImageElement, frame, qualityIndex, thumbNum, thumbFilename, false); + this.currentImageElement.dataset.index = thumbNum; + this.removeOldImages(this.currentImageElement); + } + } + + showImage(previewImage, frame, qualityIndex, thumbNum, thumbFilename, newImage = true) { + this.player.debug.log( + `Showing thumb: ${thumbFilename}. num: ${thumbNum}. qual: ${qualityIndex}. newimg: ${newImage}`, + ); + this.setImageSizeAndOffset(previewImage, frame); + + if (newImage) { + this.currentImageContainer.appendChild(previewImage); + this.currentImageElement = previewImage; + + if (!this.loadedImages.includes(thumbFilename)) { + this.loadedImages.push(thumbFilename); + } + } + + // Preload images before and after the current one + // Show higher quality of the same frame + // Each step here has a short time delay, and only continues if still hovering/seeking the same spot. This is to protect slow connections from overloading + this.preloadNearby(thumbNum, true) + .then(this.preloadNearby(thumbNum, false)) + .then(this.getHigherQuality(qualityIndex, previewImage, frame, thumbFilename)); + } + + // Remove all preview images that aren't the designated current image + removeOldImages(currentImage) { + // Get a list of all images, convert it from a DOM list to an array + Array.from(this.currentImageContainer.children).forEach(image => { + if (image.tagName.toLowerCase() !== 'img') { + return; + } + + const removeDelay = this.usingSprites ? 500 : 1000; + + if (image.dataset.index !== currentImage.dataset.index && !image.dataset.deleting) { + // Wait 200ms, as the new image can take some time to show on certain browsers (even though it was downloaded before showing). This will prevent flicker, and show some generosity towards slower clients + // First set attribute 'deleting' to prevent multi-handling of this on repeat firing of this function + // eslint-disable-next-line no-param-reassign + image.dataset.deleting = true; + + // This has to be set before the timeout - to prevent issues switching between hover and scrub + const { currentImageContainer } = this; + + setTimeout(() => { + currentImageContainer.removeChild(image); + this.player.debug.log(`Removing thumb: ${image.dataset.filename}`); + }, removeDelay); + } + }); + } + + // Preload images before and after the current one. Only if the user is still hovering/seeking the same frame + // This will only preload the lowest quality + preloadNearby(thumbNum, forward = true) { + return new Promise(resolve => { + setTimeout(() => { + const oldThumbFilename = this.thumbnails[0].frames[thumbNum].text; + + if (this.showingThumbFilename === oldThumbFilename) { + // Find the nearest thumbs with different filenames. Sometimes it'll be the next index, but in the case of sprites, it might be 100+ away + let thumbnailsClone; + if (forward) { + thumbnailsClone = this.thumbnails[0].frames.slice(thumbNum); + } else { + thumbnailsClone = this.thumbnails[0].frames.slice(0, thumbNum).reverse(); + } + + let foundOne = false; + + thumbnailsClone.forEach(frame => { + const newThumbFilename = frame.text; + + if (newThumbFilename !== oldThumbFilename) { + // Found one with a different filename. Make sure it hasn't already been loaded on this page visit + if (!this.loadedImages.includes(newThumbFilename)) { + foundOne = true; + this.player.debug.log(`Preloading thumb filename: ${newThumbFilename}`); + + const { urlPrefix } = this.thumbnails[0]; + const thumbURL = urlPrefix + newThumbFilename; + const previewImage = new Image(); + previewImage.src = thumbURL; + previewImage.onload = () => { + this.player.debug.log(`Preloaded thumb filename: ${newThumbFilename}`); + if (!this.loadedImages.includes(newThumbFilename)) + this.loadedImages.push(newThumbFilename); + + // We don't resolve until the thumb is loaded + resolve(); + }; + } + } + }); + + // If there are none to preload then we want to resolve immediately + if (!foundOne) { + resolve(); + } + } + }, 300); + }); + } + + // If user has been hovering current image for half a second, look for a higher quality one + getHigherQuality(currentQualityIndex, previewImage, frame, thumbFilename) { + if (currentQualityIndex < this.thumbnails.length - 1) { + // Only use the higher quality version if it's going to look any better - if the current thumb is of a lower pixel density than the thumbnail container + let previewImageHeight = previewImage.naturalHeight; + + if (this.usingSprites) { + previewImageHeight = frame.h; + } + + if (previewImageHeight < this.thumbContainerHeight) { + // Recurse back to the loadImage function - show a higher quality one, but only if the viewer is on this frame for a while + setTimeout(() => { + // Make sure the mouse hasn't already moved on and started hovering at another image + if (this.showingThumbFilename === thumbFilename) { + this.player.debug.log(`Showing higher quality thumb for: ${thumbFilename}`); + this.loadImage(currentQualityIndex + 1); + } + }, 300); + } + } + } + + get currentImageContainer() { + if (this.mouseDown) { + return this.elements.scrubbing.container; + } + + return this.elements.thumb.imageContainer; + } + + get usingSprites() { + return Object.keys(this.thumbnails[0].frames[0]).includes('w'); + } + + get thumbAspectRatio() { + if (this.usingSprites) { + return this.thumbnails[0].frames[0].w / this.thumbnails[0].frames[0].h; + } + + return this.thumbnails[0].width / this.thumbnails[0].height; + } + + get thumbContainerHeight() { + if (this.mouseDown) { + // Can't use media.clientHeight - HTML5 video goes big and does black bars above and below + return Math.floor(this.player.media.clientWidth / this.thumbAspectRatio); + } + + return Math.floor(this.player.media.clientWidth / this.thumbAspectRatio / 4); + } + + get currentImageElement() { + if (this.mouseDown) { + return this.currentScrubbingImageElement; + } + + return this.currentThumbnailImageElement; + } + + set currentImageElement(element) { + if (this.mouseDown) { + this.currentScrubbingImageElement = element; + } else { + this.currentThumbnailImageElement = element; + } + } + + toggleThumbContainer(toggle = false, clearShowing = false) { + const className = this.player.config.classNames.previewThumbnails.thumbContainerShown; + this.elements.thumb.container.classList.toggle(className, toggle); + + if (!toggle && clearShowing) { + this.showingThumb = null; + this.showingThumbFilename = null; + } + } + + toggleScrubbingContainer(toggle = false) { + const className = this.player.config.classNames.previewThumbnails.scrubbingContainerShown; + this.elements.scrubbing.container.classList.toggle(className, toggle); + + if (!toggle) { + this.showingThumb = null; + this.showingThumbFilename = null; + } + } + + determineContainerAutoSizing() { + if (this.elements.thumb.imageContainer.clientHeight > 20) { + // This will prevent auto sizing in this.setThumbContainerSizeAndPos() + this.sizeSpecifiedInCSS = true; + } + } + + // Set the size to be about a quarter of the size of video. Unless option dynamicSize === false, in which case it needs to be set in CSS + setThumbContainerSizeAndPos() { + if (!this.sizeSpecifiedInCSS) { + const thumbWidth = Math.floor(this.thumbContainerHeight * this.thumbAspectRatio); + this.elements.thumb.imageContainer.style.height = `${this.thumbContainerHeight}px`; + this.elements.thumb.imageContainer.style.width = `${thumbWidth}px`; + } + + this.setThumbContainerPos(); + } + + setThumbContainerPos() { + const seekbarRect = this.player.elements.progress.getBoundingClientRect(); + const plyrRect = this.player.elements.container.getBoundingClientRect(); + const { container } = this.elements.thumb; + // Find the lowest and highest desired left-position, so we don't slide out the side of the video container + const minVal = plyrRect.left - seekbarRect.left + 10; + const maxVal = plyrRect.right - seekbarRect.left - container.clientWidth - 10; + // Set preview container position to: mousepos, minus seekbar.left, minus half of previewContainer.clientWidth + let previewPos = this.mousePosX - seekbarRect.left - container.clientWidth / 2; + + if (previewPos < minVal) { + previewPos = minVal; + } + + if (previewPos > maxVal) { + previewPos = maxVal; + } + + container.style.left = `${previewPos}px`; + } + + // Can't use 100% width, in case the video is a different aspect ratio to the video container + setScrubbingContainerSize() { + this.elements.scrubbing.container.style.width = `${this.player.media.clientWidth}px`; + // Can't use media.clientHeight - html5 video goes big and does black bars above and below + this.elements.scrubbing.container.style.height = `${this.player.media.clientWidth / this.thumbAspectRatio}px`; + } + + // Sprites need to be offset to the correct location + setImageSizeAndOffset(previewImage, frame) { + if (!this.usingSprites) { + return; + } + + // Find difference between height and preview container height + const multiplier = this.thumbContainerHeight / frame.h; + + // eslint-disable-next-line no-param-reassign + previewImage.style.height = `${Math.floor(previewImage.naturalHeight * multiplier)}px`; + // eslint-disable-next-line no-param-reassign + previewImage.style.width = `${Math.floor(previewImage.naturalWidth * multiplier)}px`; + // eslint-disable-next-line no-param-reassign + previewImage.style.left = `-${frame.x * multiplier}px`; + // eslint-disable-next-line no-param-reassign + previewImage.style.top = `-${frame.y * multiplier}px`; + } +} + +export default PreviewThumbnails; diff --git a/src/js/plugins/previewThumbnails.js b/src/js/plugins/previewThumbnails.js deleted file mode 100644 index 67367b95..00000000 --- a/src/js/plugins/previewThumbnails.js +++ /dev/null @@ -1,653 +0,0 @@ -import { createElement } from '../utils/elements'; -import { once } from '../utils/events'; -import fetch from '../utils/fetch'; -import is from '../utils/is'; -import { extend } from '../utils/objects'; -import { formatTime } from '../utils/time'; - -// Arg: vttDataString example: "WEBVTT\n\n1\n00:00:05.000 --> 00:00:10.000\n1080p-00001.jpg" -const parseVtt = vttDataString => { - const processedList = []; - const frames = vttDataString.split(/\r\n\r\n|\n\n|\r\r/); - - frames.forEach(frame => { - const result = {}; - const lines = frame.split(/\r\n|\n|\r/); - - lines.forEach(line => { - if (!is.number(result.startTime)) { - // The line with start and end times on it is the first line of interest - const matchTimes = line.match( - /([0-9]{2})?:?([0-9]{2}):([0-9]{2}).([0-9]{2,3})( ?--> ?)([0-9]{2})?:?([0-9]{2}):([0-9]{2}).([0-9]{2,3})/, - ); // Note that this currently ignores caption formatting directives that are optionally on the end of this line - fine for non-captions VTT - - if (matchTimes) { - result.startTime = - Number(matchTimes[1] || 0) * 60 * 60 + - Number(matchTimes[2]) * 60 + - Number(matchTimes[3]) + - Number(`0.${matchTimes[4]}`); - result.endTime = - Number(matchTimes[6] || 0) * 60 * 60 + - Number(matchTimes[7]) * 60 + - Number(matchTimes[8]) + - Number(`0.${matchTimes[9]}`); - } - } else if (!is.empty(line.trim()) && is.empty(result.text)) { - // If we already have the startTime, then we're definitely up to the text line(s) - const lineSplit = line.trim().split('#xywh='); - [result.text] = lineSplit; - - // If there's content in lineSplit[1], then we have sprites. If not, then it's just one frame per image - if (lineSplit[1]) { - [result.x, result.y, result.w, result.h] = lineSplit[1].split(','); - } - } - }); - - if (result.text) { - processedList.push(result); - } - }); - - return processedList; -}; - -/** - * Preview thumbnails for seek hover and scrubbing - * Seeking: Hover over the seek bar (desktop only): shows a small preview container above the seek bar - * Scrubbing: Click and drag the seek bar (desktop and mobile): shows the preview image over the entire video, as if the video is scrubbing at very high speed - * - * Notes: - * - Thumbs are set via JS settings on Plyr init, not HTML5 'track' property. Using the track property would be a bit gross, because it doesn't support custom 'kinds'. kind=metadata might be used for something else, and we want to allow multiple thumbnails tracks. Tracks must have a unique combination of 'kind' and 'label'. We would have to do something like kind=metadata,label=thumbnails1 / kind=metadata,label=thumbnails2. Square peg, round hole - * - VTT info: the image URL is relative to the VTT, not the current document. But if the url starts with a slash, it will naturally be relative to the current domain. https://support.jwplayer.com/articles/how-to-add-preview-thumbnails - * - This implementation uses multiple separate img elements. Other implementations use background-image on one element. This would be nice and simple, but Firefox and Safari have flickering issues with replacing backgrounds of larger images. It seems that YouTube perhaps only avoids this because they don't have the option for high-res previews (even the fullscreen ones, when mousedown/seeking). Images appear over the top of each other, and previous ones are discarded once the new ones have been rendered - */ - -class PreviewThumbnails { - /** - * PreviewThumbnails constructor. - * @param {Plyr} player - * @return {PreviewThumbnails} - */ - constructor(player) { - this.player = player; - this.thumbnails = []; - this.loaded = false; - this.lastMouseMoveTime = Date.now(); - this.mouseDown = false; - this.loadedImages = []; - - this.elements = { - thumb: {}, - scrubbing: {}, - }; - - this.load(); - } - - get enabled() { - return this.player.isHTML5 && this.player.isVideo && this.player.config.previewThumbnails.enabled; - } - - load() { - // Togglethe regular seek tooltip - if (this.player.elements.display.seekTooltip) { - this.player.elements.display.seekTooltip.hidden = this.enabled; - } - - if (!this.enabled) { - return; - } - - this.getThumbnails().then(() => { - if (!this.enabled) { - return; - } - - // Render DOM elements - this.render(); - - // Check to see if thumb container size was specified manually in CSS - this.determineContainerAutoSizing(); - - this.loaded = true; - }); - } - - // Download VTT files and parse them - getThumbnails() { - return new Promise(resolve => { - const { src } = this.player.config.previewThumbnails; - - if (is.empty(src)) { - throw new Error('Missing previewThumbnails.src config attribute'); - } - - // 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 - 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(); - }); - }); - } - - // Process individual VTT file - getThumbnail(url) { - return new Promise(resolve => { - fetch(url).then(response => { - const thumbnail = { - frames: parseVtt(response), - height: null, - urlPrefix: '', - }; - - // If the URLs don't start with '/', then we need to set their relative path to be the location of the VTT file - // If the URLs do start with '/', then they obviously don't need a prefix, so it will remain blank - // If the thumbnail URLs start with with none of '/', 'http://' or 'https://', then we need to set their relative path to be the location of the VTT file - if ( - !thumbnail.frames[0].text.startsWith('/') && - !thumbnail.frames[0].text.startsWith('http://') && - !thumbnail.frames[0].text.startsWith('https://') - ) { - thumbnail.urlPrefix = url.substring(0, url.lastIndexOf('/') + 1); - } - - // Download the first frame, so that we can determine/set the height of this thumbnailsDef - const tempImage = new Image(); - - tempImage.onload = () => { - thumbnail.height = tempImage.naturalHeight; - thumbnail.width = tempImage.naturalWidth; - - this.thumbnails.push(thumbnail); - - resolve(); - }; - - tempImage.src = thumbnail.urlPrefix + thumbnail.frames[0].text; - }); - }); - } - - startMove(event) { - if (!this.loaded) { - return; - } - - if (!is.event(event) || !['touchmove', 'mousemove'].includes(event.type)) { - return; - } - - // Wait until media has a duration - if (!this.player.media.duration) { - return; - } - - if (event.type === 'touchmove') { - // Calculate seek hover position as approx video seconds - this.seekTime = this.player.media.duration * (this.player.elements.inputs.seek.value / 100); - } else { - // Calculate seek hover position as approx video seconds - const clientRect = this.player.elements.progress.getBoundingClientRect(); - const percentage = (100 / clientRect.width) * (event.pageX - clientRect.left); - this.seekTime = this.player.media.duration * (percentage / 100); - - if (this.seekTime < 0) { - // The mousemove fires for 10+px out to the left - this.seekTime = 0; - } - - if (this.seekTime > this.player.media.duration - 1) { - // Took 1 second off the duration for safety, because different players can disagree on the real duration of a video - this.seekTime = this.player.media.duration - 1; - } - - this.mousePosX = event.pageX; - - // Set time text inside image container - this.elements.thumb.time.innerText = formatTime(this.seekTime); - } - - // Download and show image - this.showImageAtCurrentTime(); - } - - endMove() { - this.toggleThumbContainer(false, true); - } - - startScrubbing(event) { - // Only act on left mouse button (0), or touch device (event.button is false) - if (event.button === false || event.button === 0) { - this.mouseDown = true; - - // Wait until media has a duration - if (this.player.media.duration) { - this.toggleScrubbingContainer(true); - this.toggleThumbContainer(false, true); - - // Download and show image - this.showImageAtCurrentTime(); - } - } - } - - endScrubbing() { - this.mouseDown = false; - - // Hide scrubbing preview. But wait until the video has successfully seeked before hiding the scrubbing preview - if (Math.ceil(this.lastTime) === Math.ceil(this.player.media.currentTime)) { - // The video was already seeked/loaded at the chosen time - hide immediately - this.toggleScrubbingContainer(false); - } else { - // The video hasn't seeked yet. Wait for that - once.call(this.player, this.player.media, 'timeupdate', () => { - // Re-check mousedown - we might have already started scrubbing again - if (!this.mouseDown) { - this.toggleScrubbingContainer(false); - } - }); - } - } - - /** - * Setup hooks for Plyr and window events - */ - listeners() { - // Hide thumbnail preview - on mouse click, mouse leave (in listeners.js for now), and video play/seek. All four are required, e.g., for buffering - this.player.on('play', () => { - this.toggleThumbContainer(false, true); - }); - - this.player.on('seeked', () => { - this.toggleThumbContainer(false); - }); - - this.player.on('timeupdate', () => { - this.lastTime = this.player.media.currentTime; - }); - } - - /** - * Create HTML elements for image containers - */ - render() { - // Create HTML element: plyr__preview-thumbnail-container - this.elements.thumb.container = createElement('div', { - class: this.player.config.classNames.previewThumbnails.thumbContainer, - }); - - // Wrapper for the image for styling - this.elements.thumb.imageContainer = createElement('div', { - class: this.player.config.classNames.previewThumbnails.imageContainer, - }); - this.elements.thumb.container.appendChild(this.elements.thumb.imageContainer); - - // Create HTML element, parent+span: time text (e.g., 01:32:00) - const timeContainer = createElement('div', { - class: this.player.config.classNames.previewThumbnails.timeContainer, - }); - - this.elements.thumb.time = createElement('span', {}, '00:00'); - timeContainer.appendChild(this.elements.thumb.time); - - this.elements.thumb.container.appendChild(timeContainer); - - // Inject the whole thumb - if (is.element(this.player.elements.progress)) { - this.player.elements.progress.appendChild(this.elements.thumb.container); - } - - // Create HTML element: plyr__preview-scrubbing-container - this.elements.scrubbing.container = createElement('div', { - class: this.player.config.classNames.previewThumbnails.scrubbingContainer, - }); - - this.player.elements.wrapper.appendChild(this.elements.scrubbing.container); - } - - showImageAtCurrentTime() { - if (this.mouseDown) { - this.setScrubbingContainerSize(); - } else { - this.setThumbContainerSizeAndPos(); - } - - // 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; - - // Show the thumb container if we're not scrubbing - if (!this.mouseDown) { - 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)) { - qualityIndex = index; - } - }); - - // Only proceed if either thumbnum or thumbfilename has changed - if (thumbNum !== this.showingThumb) { - this.showingThumb = thumbNum; - this.loadImage(qualityIndex); - } - } - - // Show the image that's currently specified in this.showingThumb - loadImage(qualityIndex = 0) { - const thumbNum = this.showingThumb; - const thumbnail = this.thumbnails[qualityIndex]; - const { urlPrefix } = thumbnail; - const frame = thumbnail.frames[thumbNum]; - const thumbFilename = thumbnail.frames[thumbNum].text; - const thumbUrl = urlPrefix + thumbFilename; - - if (!this.currentImageElement || this.currentImageElement.dataset.filename !== thumbFilename) { - // If we're already loading a previous image, remove its onload handler - we don't want it to load after this one - // Only do this if not using sprites. Without sprites we really want to show as many images as possible, as a best-effort - if (this.loadingImage && this.usingSprites) { - this.loadingImage.onload = null; - } - - // We're building and adding a new image. In other implementations of similar functionality (YouTube), background image - // is instead used. But this causes issues with larger images in Firefox and Safari - switching between background - // images causes a flicker. Putting a new image over the top does not - const previewImage = new Image(); - previewImage.src = thumbUrl; - previewImage.dataset.index = thumbNum; - previewImage.dataset.filename = thumbFilename; - this.showingThumbFilename = thumbFilename; - - this.player.debug.log(`Loading image: ${thumbUrl}`); - - // For some reason, passing the named function directly causes it to execute immediately. So I've wrapped it in an anonymous function... - previewImage.onload = () => - this.showImage(previewImage, frame, qualityIndex, thumbNum, thumbFilename, true); - this.loadingImage = previewImage; - this.removeOldImages(previewImage); - } else { - // Update the existing image - this.showImage(this.currentImageElement, frame, qualityIndex, thumbNum, thumbFilename, false); - this.currentImageElement.dataset.index = thumbNum; - this.removeOldImages(this.currentImageElement); - } - } - - showImage(previewImage, frame, qualityIndex, thumbNum, thumbFilename, newImage = true) { - this.player.debug.log( - `Showing thumb: ${thumbFilename}. num: ${thumbNum}. qual: ${qualityIndex}. newimg: ${newImage}`, - ); - this.setImageSizeAndOffset(previewImage, frame); - - if (newImage) { - this.currentImageContainer.appendChild(previewImage); - this.currentImageElement = previewImage; - - if (!this.loadedImages.includes(thumbFilename)) { - this.loadedImages.push(thumbFilename); - } - } - - // Preload images before and after the current one - // Show higher quality of the same frame - // Each step here has a short time delay, and only continues if still hovering/seeking the same spot. This is to protect slow connections from overloading - this.preloadNearby(thumbNum, true) - .then(this.preloadNearby(thumbNum, false)) - .then(this.getHigherQuality(qualityIndex, previewImage, frame, thumbFilename)); - } - - // Remove all preview images that aren't the designated current image - removeOldImages(currentImage) { - // Get a list of all images, convert it from a DOM list to an array - Array.from(this.currentImageContainer.children).forEach(image => { - if (image.tagName.toLowerCase() !== 'img') { - return; - } - - const removeDelay = this.usingSprites ? 500 : 1000; - - if (image.dataset.index !== currentImage.dataset.index && !image.dataset.deleting) { - // Wait 200ms, as the new image can take some time to show on certain browsers (even though it was downloaded before showing). This will prevent flicker, and show some generosity towards slower clients - // First set attribute 'deleting' to prevent multi-handling of this on repeat firing of this function - // eslint-disable-next-line no-param-reassign - image.dataset.deleting = true; - - // This has to be set before the timeout - to prevent issues switching between hover and scrub - const { currentImageContainer } = this; - - setTimeout(() => { - currentImageContainer.removeChild(image); - this.player.debug.log(`Removing thumb: ${image.dataset.filename}`); - }, removeDelay); - } - }); - } - - // Preload images before and after the current one. Only if the user is still hovering/seeking the same frame - // This will only preload the lowest quality - preloadNearby(thumbNum, forward = true) { - return new Promise(resolve => { - setTimeout(() => { - const oldThumbFilename = this.thumbnails[0].frames[thumbNum].text; - - if (this.showingThumbFilename === oldThumbFilename) { - // Find the nearest thumbs with different filenames. Sometimes it'll be the next index, but in the case of sprites, it might be 100+ away - let thumbnailsClone; - if (forward) { - thumbnailsClone = this.thumbnails[0].frames.slice(thumbNum); - } else { - thumbnailsClone = this.thumbnails[0].frames.slice(0, thumbNum).reverse(); - } - - let foundOne = false; - - thumbnailsClone.forEach(frame => { - const newThumbFilename = frame.text; - - if (newThumbFilename !== oldThumbFilename) { - // Found one with a different filename. Make sure it hasn't already been loaded on this page visit - if (!this.loadedImages.includes(newThumbFilename)) { - foundOne = true; - this.player.debug.log(`Preloading thumb filename: ${newThumbFilename}`); - - const { urlPrefix } = this.thumbnails[0]; - const thumbURL = urlPrefix + newThumbFilename; - const previewImage = new Image(); - previewImage.src = thumbURL; - previewImage.onload = () => { - this.player.debug.log(`Preloaded thumb filename: ${newThumbFilename}`); - if (!this.loadedImages.includes(newThumbFilename)) - this.loadedImages.push(newThumbFilename); - - // We don't resolve until the thumb is loaded - resolve(); - }; - } - } - }); - - // If there are none to preload then we want to resolve immediately - if (!foundOne) { - resolve(); - } - } - }, 300); - }); - } - - // If user has been hovering current image for half a second, look for a higher quality one - getHigherQuality(currentQualityIndex, previewImage, frame, thumbFilename) { - if (currentQualityIndex < this.thumbnails.length - 1) { - // Only use the higher quality version if it's going to look any better - if the current thumb is of a lower pixel density than the thumbnail container - let previewImageHeight = previewImage.naturalHeight; - - if (this.usingSprites) { - previewImageHeight = frame.h; - } - - if (previewImageHeight < this.thumbContainerHeight) { - // Recurse back to the loadImage function - show a higher quality one, but only if the viewer is on this frame for a while - setTimeout(() => { - // Make sure the mouse hasn't already moved on and started hovering at another image - if (this.showingThumbFilename === thumbFilename) { - this.player.debug.log(`Showing higher quality thumb for: ${thumbFilename}`); - this.loadImage(currentQualityIndex + 1); - } - }, 300); - } - } - } - - get currentImageContainer() { - if (this.mouseDown) { - return this.elements.scrubbing.container; - } - - return this.elements.thumb.imageContainer; - } - - get usingSprites() { - return Object.keys(this.thumbnails[0].frames[0]).includes('w'); - } - - get thumbAspectRatio() { - if (this.usingSprites) { - return this.thumbnails[0].frames[0].w / this.thumbnails[0].frames[0].h; - } - - return this.thumbnails[0].width / this.thumbnails[0].height; - } - - get thumbContainerHeight() { - if (this.mouseDown) { - // Can't use media.clientHeight - HTML5 video goes big and does black bars above and below - return Math.floor(this.player.media.clientWidth / this.thumbAspectRatio); - } - - return Math.floor(this.player.media.clientWidth / this.thumbAspectRatio / 4); - } - - get currentImageElement() { - if (this.mouseDown) { - return this.currentScrubbingImageElement; - } - - return this.currentThumbnailImageElement; - } - - set currentImageElement(element) { - if (this.mouseDown) { - this.currentScrubbingImageElement = element; - } else { - this.currentThumbnailImageElement = element; - } - } - - toggleThumbContainer(toggle = false, clearShowing = false) { - const className = this.player.config.classNames.previewThumbnails.thumbContainerShown; - this.elements.thumb.container.classList.toggle(className, toggle); - - if (!toggle && clearShowing) { - this.showingThumb = null; - this.showingThumbFilename = null; - } - } - - toggleScrubbingContainer(toggle = false) { - const className = this.player.config.classNames.previewThumbnails.scrubbingContainerShown; - this.elements.scrubbing.container.classList.toggle(className, toggle); - - if (!toggle) { - this.showingThumb = null; - this.showingThumbFilename = null; - } - } - - determineContainerAutoSizing() { - if (this.elements.thumb.imageContainer.clientHeight > 20) { - // This will prevent auto sizing in this.setThumbContainerSizeAndPos() - this.sizeSpecifiedInCSS = true; - } - } - - // Set the size to be about a quarter of the size of video. Unless option dynamicSize === false, in which case it needs to be set in CSS - setThumbContainerSizeAndPos() { - if (!this.sizeSpecifiedInCSS) { - const thumbWidth = Math.floor(this.thumbContainerHeight * this.thumbAspectRatio); - this.elements.thumb.imageContainer.style.height = `${this.thumbContainerHeight}px`; - this.elements.thumb.imageContainer.style.width = `${thumbWidth}px`; - } - - this.setThumbContainerPos(); - } - - setThumbContainerPos() { - const seekbarRect = this.player.elements.progress.getBoundingClientRect(); - const plyrRect = this.player.elements.container.getBoundingClientRect(); - const { container } = this.elements.thumb; - // Find the lowest and highest desired left-position, so we don't slide out the side of the video container - const minVal = plyrRect.left - seekbarRect.left + 10; - const maxVal = plyrRect.right - seekbarRect.left - container.clientWidth - 10; - // Set preview container position to: mousepos, minus seekbar.left, minus half of previewContainer.clientWidth - let previewPos = this.mousePosX - seekbarRect.left - container.clientWidth / 2; - - if (previewPos < minVal) { - previewPos = minVal; - } - - if (previewPos > maxVal) { - previewPos = maxVal; - } - - container.style.left = `${previewPos}px`; - } - - // Can't use 100% width, in case the video is a different aspect ratio to the video container - setScrubbingContainerSize() { - this.elements.scrubbing.container.style.width = `${this.player.media.clientWidth}px`; - // Can't use media.clientHeight - html5 video goes big and does black bars above and below - this.elements.scrubbing.container.style.height = `${this.player.media.clientWidth / this.thumbAspectRatio}px`; - } - - // Sprites need to be offset to the correct location - setImageSizeAndOffset(previewImage, frame) { - if (!this.usingSprites) { - return; - } - - // Find difference between height and preview container height - const multiplier = this.thumbContainerHeight / frame.h; - - // eslint-disable-next-line no-param-reassign - previewImage.style.height = `${Math.floor(previewImage.naturalHeight * multiplier)}px`; - // eslint-disable-next-line no-param-reassign - previewImage.style.width = `${Math.floor(previewImage.naturalWidth * multiplier)}px`; - // eslint-disable-next-line no-param-reassign - previewImage.style.left = `-${frame.x * multiplier}px`; - // eslint-disable-next-line no-param-reassign - previewImage.style.top = `-${frame.y * multiplier}px`; - } -} - -export default PreviewThumbnails; diff --git a/src/js/plugins/vimeo.js b/src/js/plugins/vimeo.js index bef48708..91019abf 100644 --- a/src/js/plugins/vimeo.js +++ b/src/js/plugins/vimeo.js @@ -9,7 +9,7 @@ import { createElement, replaceElement, toggleClass } from '../utils/elements'; import { triggerEvent } from '../utils/events'; import fetch from '../utils/fetch'; import is from '../utils/is'; -import loadScript from '../utils/loadScript'; +import loadScript from '../utils/load-script'; import { extend } from '../utils/objects'; import { format, stripHTML } from '../utils/strings'; import { setAspectRatio } from '../utils/style'; diff --git a/src/js/plugins/youtube.js b/src/js/plugins/youtube.js index 34c5de7e..31d22bb4 100644 --- a/src/js/plugins/youtube.js +++ b/src/js/plugins/youtube.js @@ -7,8 +7,8 @@ import { createElement, replaceElement, toggleClass } from '../utils/elements'; import { triggerEvent } from '../utils/events'; import fetch from '../utils/fetch'; import is from '../utils/is'; -import loadImage from '../utils/loadImage'; -import loadScript from '../utils/loadScript'; +import loadImage from '../utils/load-image'; +import loadScript from '../utils/load-script'; import { extend } from '../utils/objects'; import { format, generateId } from '../utils/strings'; import { setAspectRatio } from '../utils/style'; -- cgit v1.2.3 From e978bc869070aa9740b6e400b9d20da6b11c95db Mon Sep 17 00:00:00 2001 From: Sascha Greuel Date: Tue, 27 Aug 2019 19:28:51 +0200 Subject: Fixed ads configuration --- src/js/plugins/ads.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/js/plugins') diff --git a/src/js/plugins/ads.js b/src/js/plugins/ads.js index db55e499..6b4fca10 100644 --- a/src/js/plugins/ads.js +++ b/src/js/plugins/ads.js @@ -136,7 +136,7 @@ class Ads { cb: Date.now(), AV_WIDTH: 640, AV_HEIGHT: 480, - AV_CDIM2: this.publisherId, + AV_CDIM2: config.publisherId, }; const base = 'https://go.aniview.com/api/adserver6/vast/'; -- cgit v1.2.3 From 627df20b6d50e6f9d9ae9e0cadddacd3a6f83ba1 Mon Sep 17 00:00:00 2001 From: Dustin Harrell Date: Mon, 23 Sep 2019 18:26:49 -0400 Subject: #615: updates to vimeo and youtube plugins to ensure that loading classes are added as content is buffering --- src/js/plugins/vimeo.js | 8 ++++++++ src/js/plugins/youtube.js | 6 ++++++ 2 files changed, 14 insertions(+) (limited to 'src/js/plugins') diff --git a/src/js/plugins/vimeo.js b/src/js/plugins/vimeo.js index 91019abf..8df5ad15 100644 --- a/src/js/plugins/vimeo.js +++ b/src/js/plugins/vimeo.js @@ -335,6 +335,14 @@ const vimeo = { } }); + player.embed.on('bufferstart', () => { + triggerEvent.call(player, player.media, 'waiting'); + }); + + player.embed.on('bufferend', () => { + triggerEvent.call(player, player.media, 'playing'); + }); + player.embed.on('play', () => { assurePlaybackState.call(player, true); triggerEvent.call(player, player.media, 'playing'); diff --git a/src/js/plugins/youtube.js b/src/js/plugins/youtube.js index 31d22bb4..ba5d8de9 100644 --- a/src/js/plugins/youtube.js +++ b/src/js/plugins/youtube.js @@ -416,6 +416,12 @@ const youtube = { break; + case 3: + // Trigger waiting event to add loading classes to container as the video buffers. + triggerEvent.call(player, player.media, 'waiting'); + + break; + default: break; } -- cgit v1.2.3 From bfcb7133cb682e801a4b46003853b3aa631afbbb Mon Sep 17 00:00:00 2001 From: Shravan Rajinikanth Date: Sun, 19 Jan 2020 06:05:12 -0800 Subject: Fixed Plyr container not resizing responsively --- src/js/plugins/preview-thumbnails.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/js/plugins') diff --git a/src/js/plugins/preview-thumbnails.js b/src/js/plugins/preview-thumbnails.js index 61021d64..930c055d 100644 --- a/src/js/plugins/preview-thumbnails.js +++ b/src/js/plugins/preview-thumbnails.js @@ -540,8 +540,8 @@ class PreviewThumbnails { get thumbContainerHeight() { if (this.mouseDown) { - // Can't use media.clientHeight - HTML5 video goes big and does black bars above and below - return Math.floor(this.player.media.clientWidth / this.thumbAspectRatio); + const { height } = fitRatio(this.thumbAspectRatio, { width: this.player.media.clientWidth, height: this.player.media.clientHeight }); + return height; } return Math.floor(this.player.media.clientWidth / this.thumbAspectRatio / 4); @@ -624,9 +624,9 @@ class PreviewThumbnails { // Can't use 100% width, in case the video is a different aspect ratio to the video container setScrubbingContainerSize() { - this.elements.scrubbing.container.style.width = `${this.player.media.clientWidth}px`; - // Can't use media.clientHeight - html5 video goes big and does black bars above and below - this.elements.scrubbing.container.style.height = `${this.player.media.clientWidth / this.thumbAspectRatio}px`; + const { width, height } = fitRatio(this.thumbAspectRatio, { width: this.player.media.clientWidth, height: this.player.media.clientHeight }); + this.elements.scrubbing.container.style.width = `${width}px`; + this.elements.scrubbing.container.style.height = `${height}px`; } // Sprites need to be offset to the correct location @@ -639,14 +639,29 @@ class PreviewThumbnails { const multiplier = this.thumbContainerHeight / frame.h; // eslint-disable-next-line no-param-reassign - previewImage.style.height = `${Math.floor(previewImage.naturalHeight * multiplier)}px`; + previewImage.style.height = `${previewImage.naturalHeight * multiplier}px`; // eslint-disable-next-line no-param-reassign - previewImage.style.width = `${Math.floor(previewImage.naturalWidth * multiplier)}px`; + previewImage.style.width = `${previewImage.naturalWidth * multiplier}px`; // eslint-disable-next-line no-param-reassign previewImage.style.left = `-${frame.x * multiplier}px`; // eslint-disable-next-line no-param-reassign previewImage.style.top = `-${frame.y * multiplier}px`; } + + fitRatio(ratio, outer) { + const targetRatio = outer.width / outer.height; + + const result = {}; + if (ratio > targetRatio) { + result.width = outer.width; + result.height = (1 / ratio) * outer.width; + } else { + result.height = outer.height; + result.width = ratio * outer.height; + } + + return result; + } } export default PreviewThumbnails; -- cgit v1.2.3 From b6da2702a2bb11da63009749954efc3dc2ba0942 Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Tue, 21 Jan 2020 22:30:58 +0000 Subject: Fix reference --- src/js/plugins/preview-thumbnails.js | 39 ++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'src/js/plugins') diff --git a/src/js/plugins/preview-thumbnails.js b/src/js/plugins/preview-thumbnails.js index 930c055d..44e6ace7 100644 --- a/src/js/plugins/preview-thumbnails.js +++ b/src/js/plugins/preview-thumbnails.js @@ -63,6 +63,20 @@ const parseVtt = vttDataString => { * - This implementation uses multiple separate img elements. Other implementations use background-image on one element. This would be nice and simple, but Firefox and Safari have flickering issues with replacing backgrounds of larger images. It seems that YouTube perhaps only avoids this because they don't have the option for high-res previews (even the fullscreen ones, when mousedown/seeking). Images appear over the top of each other, and previous ones are discarded once the new ones have been rendered */ +const fitRatio = (ratio, outer) => { + const targetRatio = outer.width / outer.height; + const result = {}; + if (ratio > targetRatio) { + result.width = outer.width; + result.height = (1 / ratio) * outer.width; + } else { + result.height = outer.height; + result.width = ratio * outer.height; + } + + return result; +}; + class PreviewThumbnails { /** * PreviewThumbnails constructor. @@ -540,7 +554,10 @@ class PreviewThumbnails { get thumbContainerHeight() { if (this.mouseDown) { - const { height } = fitRatio(this.thumbAspectRatio, { width: this.player.media.clientWidth, height: this.player.media.clientHeight }); + const { height } = fitRatio(this.thumbAspectRatio, { + width: this.player.media.clientWidth, + height: this.player.media.clientHeight, + }); return height; } @@ -624,7 +641,10 @@ class PreviewThumbnails { // Can't use 100% width, in case the video is a different aspect ratio to the video container setScrubbingContainerSize() { - const { width, height } = fitRatio(this.thumbAspectRatio, { width: this.player.media.clientWidth, height: this.player.media.clientHeight }); + const { width, height } = fitRatio(this.thumbAspectRatio, { + width: this.player.media.clientWidth, + height: this.player.media.clientHeight, + }); this.elements.scrubbing.container.style.width = `${width}px`; this.elements.scrubbing.container.style.height = `${height}px`; } @@ -647,21 +667,6 @@ class PreviewThumbnails { // eslint-disable-next-line no-param-reassign previewImage.style.top = `-${frame.y * multiplier}px`; } - - fitRatio(ratio, outer) { - const targetRatio = outer.width / outer.height; - - const result = {}; - if (ratio > targetRatio) { - result.width = outer.width; - result.height = (1 / ratio) * outer.width; - } else { - result.height = outer.height; - result.width = ratio * outer.height; - } - - return result; - } } export default PreviewThumbnails; -- cgit v1.2.3 From 61a24eab765f09bdcff92c872c6882d79cf4d180 Mon Sep 17 00:00:00 2001 From: ydylla Date: Sat, 1 Feb 2020 16:32:14 +0100 Subject: add previewThumbnails source setter #1369 --- src/js/plugins/preview-thumbnails.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/js/plugins') diff --git a/src/js/plugins/preview-thumbnails.js b/src/js/plugins/preview-thumbnails.js index 44e6ace7..aa06edf4 100644 --- a/src/js/plugins/preview-thumbnails.js +++ b/src/js/plugins/preview-thumbnails.js @@ -104,7 +104,7 @@ class PreviewThumbnails { } load() { - // Togglethe regular seek tooltip + // Toggle the regular seek tooltip if (this.player.elements.display.seekTooltip) { this.player.elements.display.seekTooltip.hidden = this.enabled; } @@ -328,6 +328,15 @@ class PreviewThumbnails { this.player.elements.wrapper.appendChild(this.elements.scrubbing.container); } + destroy() { + if (this.elements.thumb.container) { + this.elements.thumb.container.remove(); + } + if (this.elements.scrubbing.container) { + this.elements.scrubbing.container.remove(); + } + } + showImageAtCurrentTime() { if (this.mouseDown) { this.setScrubbingContainerSize(); -- cgit v1.2.3 From 9075ea189a013f7c9ddc0a473d7efbd96ac557f8 Mon Sep 17 00:00:00 2001 From: ydylla Date: Sat, 8 Feb 2020 18:59:09 +0100 Subject: fix scrubbing for chrome android & hide thumb preview on touchend Chrome android sends TouchEvent which does not have a button property. --- src/js/plugins/preview-thumbnails.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/js/plugins') diff --git a/src/js/plugins/preview-thumbnails.js b/src/js/plugins/preview-thumbnails.js index 44e6ace7..6cd09ef2 100644 --- a/src/js/plugins/preview-thumbnails.js +++ b/src/js/plugins/preview-thumbnails.js @@ -239,8 +239,8 @@ class PreviewThumbnails { } startScrubbing(event) { - // Only act on left mouse button (0), or touch device (event.button is false) - if (event.button === false || event.button === 0) { + // Only act on left mouse button (0), or touch device (event.button does not exist or is false) + if (is.nullOrUndefined(event.button) || event.button === false || event.button === 0) { this.mouseDown = true; // Wait until media has a duration -- cgit v1.2.3 From 97f8093a8df1fd7462512d43716bcd7601fecb18 Mon Sep 17 00:00:00 2001 From: ydylla Date: Sat, 8 Feb 2020 19:04:26 +0100 Subject: allows to set only width or height for thumb css size Also fixes sprites when css thumb size is used --- src/js/plugins/preview-thumbnails.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/js/plugins') diff --git a/src/js/plugins/preview-thumbnails.js b/src/js/plugins/preview-thumbnails.js index 44e6ace7..8256c811 100644 --- a/src/js/plugins/preview-thumbnails.js +++ b/src/js/plugins/preview-thumbnails.js @@ -561,6 +561,11 @@ class PreviewThumbnails { return height; } + // If css is used this needs to return the css height for sprites to work (see setImageSizeAndOffset) + if (this.sizeSpecifiedInCSS) { + return this.elements.thumb.imageContainer.clientHeight; + } + return Math.floor(this.player.media.clientWidth / this.thumbAspectRatio / 4); } @@ -601,7 +606,7 @@ class PreviewThumbnails { } determineContainerAutoSizing() { - if (this.elements.thumb.imageContainer.clientHeight > 20) { + if (this.elements.thumb.imageContainer.clientHeight > 20 || this.elements.thumb.imageContainer.clientWidth > 20) { // This will prevent auto sizing in this.setThumbContainerSizeAndPos() this.sizeSpecifiedInCSS = true; } @@ -613,6 +618,12 @@ class PreviewThumbnails { const thumbWidth = Math.floor(this.thumbContainerHeight * this.thumbAspectRatio); this.elements.thumb.imageContainer.style.height = `${this.thumbContainerHeight}px`; this.elements.thumb.imageContainer.style.width = `${thumbWidth}px`; + } else if (this.elements.thumb.imageContainer.clientHeight > 20 && this.elements.thumb.imageContainer.clientWidth < 20) { + const thumbWidth = Math.floor(this.elements.thumb.imageContainer.clientHeight * this.thumbAspectRatio); + this.elements.thumb.imageContainer.style.width = `${thumbWidth}px`; + } else if (this.elements.thumb.imageContainer.clientHeight < 20 && this.elements.thumb.imageContainer.clientWidth > 20) { + const thumbHeight = Math.floor(this.elements.thumb.imageContainer.clientWidth / this.thumbAspectRatio); + this.elements.thumb.imageContainer.style.height = `${thumbHeight}px`; } this.setThumbContainerPos(); -- cgit v1.2.3 From 90dc985657190f08e91686cdcf404a106c498511 Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Sat, 8 Feb 2020 23:09:41 +0000 Subject: Clean up speed options logic --- src/js/plugins/vimeo.js | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/js/plugins') diff --git a/src/js/plugins/vimeo.js b/src/js/plugins/vimeo.js index 8df5ad15..9529f2cd 100644 --- a/src/js/plugins/vimeo.js +++ b/src/js/plugins/vimeo.js @@ -196,12 +196,6 @@ const vimeo = { .then(() => { speed = input; triggerEvent.call(player, player.media, 'ratechange'); - }) - .catch(error => { - // Hide menu item (and menu if empty) - if (error.name === 'Error') { - controls.setSpeedMenu.call(player, []); - } }); }, }); -- cgit v1.2.3 From 7ca74f48bc8d84de696c3e4a50ed4167d67ddaf5 Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Mon, 10 Feb 2020 11:24:38 +0000 Subject: Added vimeo options to hide controls and set referrerPolicy --- src/js/plugins/vimeo.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/js/plugins') diff --git a/src/js/plugins/vimeo.js b/src/js/plugins/vimeo.js index 9529f2cd..7d796858 100644 --- a/src/js/plugins/vimeo.js +++ b/src/js/plugins/vimeo.js @@ -99,6 +99,11 @@ const vimeo = { iframe.setAttribute('allowtransparency', ''); iframe.setAttribute('allow', 'autoplay'); + // Set the referrer policy if required + if (!is.empty(config.referrerPolicy)) { + iframe.setAttribute('referrerPolicy', config.referrerPolicy); + } + // Get poster, if already set const { poster } = player; // Inject the package @@ -191,12 +196,10 @@ const vimeo = { return speed; }, set(input) { - player.embed - .setPlaybackRate(input) - .then(() => { - speed = input; - triggerEvent.call(player, player.media, 'ratechange'); - }); + player.embed.setPlaybackRate(input).then(() => { + speed = input; + triggerEvent.call(player, player.media, 'ratechange'); + }); }, }); -- cgit v1.2.3 From 1619510dcf9e3ccc1693caa20a173aaf2789e346 Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Mon, 10 Feb 2020 18:34:05 +0000 Subject: Speed settings logic improvements --- src/js/plugins/vimeo.js | 17 +++++++++++------ src/js/plugins/youtube.js | 4 +++- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'src/js/plugins') diff --git a/src/js/plugins/vimeo.js b/src/js/plugins/vimeo.js index 7d796858..fa965d8e 100644 --- a/src/js/plugins/vimeo.js +++ b/src/js/plugins/vimeo.js @@ -42,23 +42,28 @@ function assurePlaybackState(play) { const vimeo = { setup() { + const player = this; + // Add embed class for responsive - toggleClass(this.elements.wrapper, this.config.classNames.embed, true); + toggleClass(player.elements.wrapper, player.config.classNames.embed, true); + + // Set speed options from config + player.options.speed = player.config.speed.options; // Set intial ratio - setAspectRatio.call(this); + setAspectRatio.call(player); // Load the SDK if not already if (!is.object(window.Vimeo)) { - loadScript(this.config.urls.vimeo.sdk) + loadScript(player.config.urls.vimeo.sdk) .then(() => { - vimeo.ready.call(this); + vimeo.ready.call(player); }) .catch(error => { - this.debug.warn('Vimeo SDK (player.js) failed to load', error); + player.debug.warn('Vimeo SDK (player.js) failed to load', error); }); } else { - vimeo.ready.call(this); + vimeo.ready.call(player); } }, diff --git a/src/js/plugins/youtube.js b/src/js/plugins/youtube.js index ba5d8de9..8c65b1dc 100644 --- a/src/js/plugins/youtube.js +++ b/src/js/plugins/youtube.js @@ -297,7 +297,9 @@ const youtube = { }); // Get available speeds - player.options.speed = instance.getAvailablePlaybackRates(); + const speeds = instance.getAvailablePlaybackRates(); + // Filter based on config + player.options.speed = speeds.filter(s => player.config.speed.options.includes(s)); // Set the tabindex to avoid focus entering iframe if (player.supported.ui) { -- cgit v1.2.3 From 0cf5d25a7f28203553b1fa2db5c600995c284b65 Mon Sep 17 00:00:00 2001 From: Hugues Date: Thu, 20 Feb 2020 12:57:47 +0000 Subject: catch error in setPlaybackRate on Vimeo --- src/js/plugins/vimeo.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/js/plugins') diff --git a/src/js/plugins/vimeo.js b/src/js/plugins/vimeo.js index fa965d8e..010cf5f7 100644 --- a/src/js/plugins/vimeo.js +++ b/src/js/plugins/vimeo.js @@ -204,6 +204,9 @@ const vimeo = { player.embed.setPlaybackRate(input).then(() => { speed = input; triggerEvent.call(player, player.media, 'ratechange'); + }).catch(() => { + // Cannot set Playback Rate, Video is probably not on Pro account + player.options.speed = [1]; }); }, }); -- cgit v1.2.3 From 81b41be750c9eddbabafdbd304614d827cd0ca82 Mon Sep 17 00:00:00 2001 From: max Date: Tue, 25 Feb 2020 17:53:44 +0100 Subject: preview-thumbnails via src:callback() --- src/js/plugins/preview-thumbnails.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/js/plugins') diff --git a/src/js/plugins/preview-thumbnails.js b/src/js/plugins/preview-thumbnails.js index 86eeebc8..e313a01f 100644 --- a/src/js/plugins/preview-thumbnails.js +++ b/src/js/plugins/preview-thumbnails.js @@ -137,19 +137,31 @@ class PreviewThumbnails { throw new Error('Missing previewThumbnails.src config attribute'); } - // 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 - const promises = urls.map(u => this.getThumbnail(u)); - - Promise.all(promises).then(() => { + // Resolve promise + const exec_resolve = () => { // 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(); - }); + }; + // Via callback() + if( typeof(src) == 'function' ) { + // Ask + this.thumbnails = src(); + // Resolve + exec_resolve(); + } + // VTT urls + else { + // 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 + const promises = urls.map(u => this.getThumbnail(u)); + // Resolve + Promise.all(promises).then(exec_resolve); + } }); } -- cgit v1.2.3 From b212b25a9eca8a440a05d53b744aa56f646b2929 Mon Sep 17 00:00:00 2001 From: max Date: Wed, 26 Feb 2020 10:35:08 +0100 Subject: Fixes --- src/js/plugins/preview-thumbnails.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/js/plugins') diff --git a/src/js/plugins/preview-thumbnails.js b/src/js/plugins/preview-thumbnails.js index e313a01f..7e9f0dc9 100644 --- a/src/js/plugins/preview-thumbnails.js +++ b/src/js/plugins/preview-thumbnails.js @@ -138,7 +138,7 @@ class PreviewThumbnails { } // Resolve promise - const exec_resolve = () => { + const resolvePromise = () => { // Sort smallest to biggest (e.g., [120p, 480p, 1080p]) this.thumbnails.sort((x, y) => x.height - y.height); @@ -147,11 +147,14 @@ class PreviewThumbnails { resolve(); }; // Via callback() - if( typeof(src) == 'function' ) { + if (typeof(src) == 'function') { // Ask - this.thumbnails = src(); - // Resolve - exec_resolve(); + let that = this; + src(function(thumbnails) { + that.thumbnails = thumbnails; + // Resolve + resolvePromise(); + }); } // VTT urls else { @@ -160,7 +163,7 @@ class PreviewThumbnails { // 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)); // Resolve - Promise.all(promises).then(exec_resolve); + Promise.all(promises).then(resolvePromise); } }); } -- cgit v1.2.3 From ace682abbdeba13ea3664e9dde38a903a4a5da5e Mon Sep 17 00:00:00 2001 From: max Date: Wed, 26 Feb 2020 10:41:26 +0100 Subject: Fixes2 --- src/js/plugins/preview-thumbnails.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/js/plugins') diff --git a/src/js/plugins/preview-thumbnails.js b/src/js/plugins/preview-thumbnails.js index 7e9f0dc9..4c13ab33 100644 --- a/src/js/plugins/preview-thumbnails.js +++ b/src/js/plugins/preview-thumbnails.js @@ -138,7 +138,7 @@ class PreviewThumbnails { } // Resolve promise - const resolvePromise = () => { + const sortAndResolve = () => { // Sort smallest to biggest (e.g., [120p, 480p, 1080p]) this.thumbnails.sort((x, y) => x.height - y.height); @@ -147,13 +147,13 @@ class PreviewThumbnails { resolve(); }; // Via callback() - if (typeof(src) == 'function') { + if (is.function(src)) { // Ask let that = this; src(function(thumbnails) { that.thumbnails = thumbnails; // Resolve - resolvePromise(); + sortAndResolve(); }); } // VTT urls @@ -163,7 +163,7 @@ class PreviewThumbnails { // 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)); // Resolve - Promise.all(promises).then(resolvePromise); + Promise.all(promises).then(sortAndResolve); } }); } -- cgit v1.2.3 From fd353225c27fa210a036b87a847336bf10957ed1 Mon Sep 17 00:00:00 2001 From: Steejo Date: Mon, 9 Mar 2020 23:18:19 +0000 Subject: Ads plugin fixes to allow multiple VAST requests --- src/js/plugins/ads.js | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'src/js/plugins') diff --git a/src/js/plugins/ads.js b/src/js/plugins/ads.js index 6b4fca10..79e6e5d9 100644 --- a/src/js/plugins/ads.js +++ b/src/js/plugins/ads.js @@ -172,6 +172,17 @@ class Ads { // 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); + // 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, + event => this.onAdsManagerLoaded(event), + false, + ); + this.loader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, error => this.onAdError(error), false); + // Request video ads to be pre-loaded this.requestAds(); } @@ -183,17 +194,6 @@ class Ads { const { container } = this.player.elements; 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, - event => this.onAdsManagerLoaded(event), - false, - ); - this.loader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, error => this.onAdError(error), false); - // Request video ads const request = new google.ima.AdsRequest(); request.adTagUrl = this.tagUrl; @@ -369,7 +369,14 @@ class Ads { // 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 (player.ended){ + this.loadAds(); + } + else + { + // The SDK won't allow new ads to be called without receiving a contentComplete() + this.loader.contentComplete(); + } break; @@ -563,6 +570,8 @@ class Ads { this.on('loaded', resolve); this.player.debug.log(this.manager); }); + // Now that the manager has been destroyed set it to also be un-initialized + this.initialized = false; // Now request some new advertisements this.requestAds(); -- cgit v1.2.3 From 71928443f317e624ab94ff18e207447f06f745ad Mon Sep 17 00:00:00 2001 From: ydylla Date: Mon, 23 Mar 2020 22:50:19 +0100 Subject: silence all internal play promises --- src/js/plugins/ads.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/js/plugins') diff --git a/src/js/plugins/ads.js b/src/js/plugins/ads.js index 6b4fca10..62def372 100644 --- a/src/js/plugins/ads.js +++ b/src/js/plugins/ads.js @@ -11,6 +11,7 @@ import { triggerEvent } from '../utils/events'; import i18n from '../utils/i18n'; import is from '../utils/is'; import loadScript from '../utils/load-script'; +import { silencePromise } from '../utils/promise'; import { formatTime } from '../utils/time'; import { buildUrlParams } from '../utils/urls'; @@ -510,7 +511,7 @@ class Ads { this.playing = false; // Play video - this.player.media.play(); + silencePromise(this.player.media.play()); } /** -- cgit v1.2.3