(function () { var defaults = { width: 0, height: 0, basePath: "" }, extend = function () { var args, target, i, object, property; args = Array.prototype.slice.call(arguments); target = args.shift() || {}; for (i in args) { object = args[i]; for (property in object) { if (object.hasOwnProperty(property)) { if (typeof object[property] === 'object') { target[property] = extend(target[property], object[property]); } else { target[property] = object[property]; } } } } return target; }, getComputedStyle = function (el, pseudo) { return function (prop) { if (window.getComputedStyle) { return window.getComputedStyle(el, pseudo)[prop]; } else { return el.currentStyle[prop]; } }; }, offsetParent = function (el) { if (el.nodeName !== 'HTML' && getComputedStyle(el)('position') === 'static') { return offsetParent(el.offsetParent); } return el; }, getScrollOffset = function () { if (window.pageXOffset) { return { x: window.pageXOffset, y: window.pageYOffset }; } return { x: document.documentElement.scrollLeft, y: document.documentElement.scrollTop }; }, parseImageLink = function (imglocation) { var lsrc, clip, hashindex, hashstring; hashindex = imglocation.indexOf('#'); if (hashindex === -1) { return { src: imglocation, w: 0, h: 0, x: 0, y: 0 }; } lsrc = imglocation.substring(0, hashindex); hashstring = imglocation.substring(hashindex + 1); if (hashstring.substring(0, 5) !== 'xywh=') { return { src: defaults.basePath + lsrc, w: 0, h: 0, x: 0, y: 0 }; } var data = hashstring.substring(5).split(','); return { src: defaults.basePath + lsrc, w: parseInt(data[2]), h: parseInt(data[3]), x: parseInt(data[0]), y: parseInt(data[1]) }; }; videojs.registerPlugin('thumbnails', function (options) { var div, settings, img, player, progressControl, duration, moveListener, moveCancel, thumbTrack; defaults.basePath = options.basePath || defaults.basePath; settings = extend({}, defaults, options); player = this; var numtracks = player.textTracks().length; if (numtracks === 0) { return; } i = 0; while (i < numtracks) { if (player.textTracks()[i].kind === 'metadata') { thumbTrack = player.textTracks()[i]; thumbTrack.mode = 'hidden'; break; } i++; } (function () { var progressControl, addFakeActive, removeFakeActive; if (navigator.userAgent.toLowerCase().indexOf("android") !== -1) { progressControl = player.controlBar.progressControl; addFakeActive = function () { progressControl.addClass('fake-active'); }; removeFakeActive = function () { progressControl.removeClass('fake-active'); }; progressControl.on('touchstart', addFakeActive); progressControl.on('touchend', removeFakeActive); progressControl.on('touchcancel', removeFakeActive); } })(); div = document.createElement('div'); div.className = 'vjs-thumbnail-holder'; img = document.createElement('img'); div.appendChild(img); img.className = 'vjs-thumbnail'; duration = player.duration(); player.on('durationchange', function (event) { duration = player.duration(); }); player.on('loadedmetadata', function (event) { duration = player.duration(); }); progressControl = player.controlBar.progressControl; progressHolder = progressControl.seekBar; progressHolder.el().appendChild(div); div.style.background = 'transparent'; div.style.border = 'none'; div.style.boxShadow = 'none'; var debounceTimeout; // Define a função moveListener que é ativada em eventos de movimento do mouse ou toque moveListener = function (event) { // Declaração de variáveis ​​usadas na função var mouseTime, time, active, left, setting, pageX, right, width, halfWidth, pageXOffset, clientRect; // Inicializa a variável active com 0 active = 0; // Obtém o deslocamento de scroll horizontal da janela pageXOffset = getScrollOffset().x; // Obtém as dimensões e a posição do elemento que contém a barra de progresso clientRect = offsetParent(progressHolder.el()).getBoundingClientRect(); // Calcula a posição da borda direita da barra de progresso right = (clientRect.width || clientRect.right) + pageXOffset; // Obtém a posição do mouse no eixo X a partir do evento pageX = event.pageX; // Se o evento for um evento de toque, obtém a posição do toque no eixo X if (event.changedTouches) { pageX = event.changedTouches[0].pageX; } // Calcula a posição do mouse relativa ao lado esquerdo da barra de progresso left = pageX || (event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft); left -= offsetParent(progressHolder.el()).getBoundingClientRect().left + pageXOffset; // Converte a posição do mouse em um tempo no vídeo mouseTime = Math.floor(left / progressHolder.width() * duration); // Inicializa um contador e verifica se há alguma pista de thumbnail associada ao tempo atual do mouse var cnum = thumbTrack && thumbTrack.cues.length; i = 0; while (i < cnum) { var ccue = thumbTrack.cues[i]; if (ccue.startTime <= mouseTime && ccue.endTime >= mouseTime) { // Se encontrou uma pista, obtém as configurações da thumbnail da pista setting = parseImageLink(ccue.text); break; } i++; } // Se não encontrou uma pista, retorna early if (typeof setting === 'undefined') { return; } // Obtém o nome do arquivo da URL atual da imagem e a URL da configuração var lastImgSrc = img.src.split('/').pop(); var settingSrc = setting.src.split('/').pop(); // Se a URL da configuração for diferente da URL atual, atualiza a URL da imagem if (setting.src && lastImgSrc != settingSrc) { img.src = "./RedeCanaisVTTS/vtts/RCServer01/" + setting.src; } // Se as dimensões da imagem não foram especificadas, usa as dimensões padrão if (setting.w === 0) { setting.w = settings.width; } if (setting.h === 0) { setting.h = settings.height; } // Se as dimensões da div forem diferentes das dimensões da configuração, atualiza as dimensões da div if (div.style.width != setting.w || div.style.height != setting.h) { div.style.width = setting.w + 'px'; div.style.height = setting.h + 'px'; } // Atualiza a posição e o clipping da imagem de acordo com as configurações img.style.left = -(setting.x) + 'px'; img.style.top = -(setting.y) + 'px'; img.style.clip = 'rect(' + setting.y + 'px,' + (setting.w + setting.x) + 'px,' + (setting.y + setting.h) + 'px,' + setting.x + 'px)'; // Calcula a nova posição da div com base na posição do mouse e nas dimensões da imagem width = setting.w; halfWidth = width / 2; if ((left + halfWidth) > right) { left = right - width; } else if (left < halfWidth) { left = 0; } else { left = left - halfWidth; } // Atualiza a posição da div div.style.left = left + 'px'; }; progressControl.on('mousemove', moveListener); progressControl.on('touchmove', moveListener); // Inicializa a variável timeout com null var timeout = null; // Define a função moveCancel com debounce de 500ms moveCancel = function (event) { // Cancela o timeout anterior, se houver clearTimeout(timeout); // Define um novo timeout de 500ms timeout = setTimeout(function () { div.style.left = '-9999px'; }, 5000); }; progressControl.on('mouseout', moveCancel); progressControl.on('touchcancel', moveCancel); progressControl.on('touchend', moveCancel); player.on('userinactive', moveCancel); }); })();