import events from 'events'; import browser from 'browser'; import appRouter from 'appRouter'; import loading from 'loading'; /* globals YT */ function zoomIn(elem, iterations) { const keyframes = [ { transform: 'scale3d(.2, .2, .2) ', opacity: '.6', offset: 0 }, { transform: 'none', opacity: '1', offset: 1 } ]; const timing = { duration: 240, iterations: iterations }; return elem.animate(keyframes, timing); } function createMediaElement(instance, options) { return new Promise(function (resolve, reject) { const dlg = document.querySelector('.youtubePlayerContainer'); if (!dlg) { import('css!./style').then(() => { loading.show(); const dlg = document.createElement('div'); dlg.classList.add('youtubePlayerContainer'); if (options.fullscreen) { dlg.classList.add('onTop'); } dlg.innerHTML = '
'; const videoElement = dlg.querySelector('#player'); document.body.insertBefore(dlg, document.body.firstChild); instance.videoDialog = dlg; if (options.fullscreen && dlg.animate && !browser.slow) { zoomIn(dlg, 1).onfinish = function () { resolve(videoElement); }; } else { resolve(videoElement); } }); } else { resolve(dlg.querySelector('#player')); } }); } function onVideoResize() { const instance = this; const player = instance.currentYoutubePlayer; const dlg = instance.videoDialog; if (player && dlg) { player.setSize(dlg.offsetWidth, dlg.offsetHeight); } } function clearTimeUpdateInterval(instance) { if (instance.timeUpdateInterval) { clearInterval(instance.timeUpdateInterval); } instance.timeUpdateInterval = null; } function onEndedInternal(instance) { clearTimeUpdateInterval(instance); const resizeListener = instance.resizeListener; if (resizeListener) { window.removeEventListener('resize', resizeListener); window.removeEventListener('orientationChange', resizeListener); instance.resizeListener = null; } const stopInfo = { src: instance._currentSrc }; events.trigger(instance, 'stopped', [stopInfo]); instance._currentSrc = null; if (instance.currentYoutubePlayer) { instance.currentYoutubePlayer.destroy(); } instance.currentYoutubePlayer = null; } // 4. The API will call this function when the video player is ready. function onPlayerReady(event) { event.target.playVideo(); } function onTimeUpdate(e) { events.trigger(this, 'timeupdate'); } function onPlaying(instance, playOptions, resolve) { if (!instance.started) { instance.started = true; resolve(); clearTimeUpdateInterval(instance); instance.timeUpdateInterval = setInterval(onTimeUpdate.bind(instance), 500); if (playOptions.fullscreen) { appRouter.showVideoOsd().then(function () { instance.videoDialog.classList.remove('onTop'); }); } else { appRouter.setTransparency('backdrop'); instance.videoDialog.classList.remove('onTop'); } import('loading').then(({default: loading}) => { loading.hide(); }); } } function setCurrentSrc(instance, elem, options) { return new Promise(function (resolve, reject) { import('queryString').then(({default: queryString}) => { instance._currentSrc = options.url; const params = queryString.parse(options.url.split('?')[1]); // 3. This function creates an