2019-01-10 15:39:37 +03:00
|
|
|
|
define(['dom', 'playbackManager', 'connectionManager', 'events', 'mediaInfo', 'layoutManager', 'focusManager', 'globalize', 'itemHelper', 'css!./upnextdialog', 'emby-button', 'flexStyles'], function (dom, playbackManager, connectionManager, events, mediaInfo, layoutManager, focusManager, globalize, itemHelper) {
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var transitionEndEventName = dom.whichTransitionEvent();
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
|
|
function seriesImageUrl(item, options) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
|
|
if (item.Type !== 'Episode') {
|
|
|
|
|
return null;
|
2018-10-23 01:05:09 +03:00
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
|
|
options = options || {};
|
|
|
|
|
options.type = options.type || "Primary";
|
|
|
|
|
|
|
|
|
|
if (options.type === 'Primary') {
|
|
|
|
|
|
|
|
|
|
if (item.SeriesPrimaryImageTag) {
|
|
|
|
|
|
|
|
|
|
options.tag = item.SeriesPrimaryImageTag;
|
|
|
|
|
|
|
|
|
|
return connectionManager.getApiClient(item.ServerId).getScaledImageUrl(item.SeriesId, options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (options.type === 'Thumb') {
|
|
|
|
|
|
|
|
|
|
if (item.SeriesThumbImageTag) {
|
|
|
|
|
|
|
|
|
|
options.tag = item.SeriesThumbImageTag;
|
|
|
|
|
|
|
|
|
|
return connectionManager.getApiClient(item.ServerId).getScaledImageUrl(item.SeriesId, options);
|
|
|
|
|
}
|
|
|
|
|
if (item.ParentThumbImageTag) {
|
|
|
|
|
|
|
|
|
|
options.tag = item.ParentThumbImageTag;
|
|
|
|
|
|
|
|
|
|
return connectionManager.getApiClient(item.ServerId).getScaledImageUrl(item.ParentThumbItemId, options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
2018-10-23 01:05:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function imageUrl(item, options) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
|
|
options = options || {};
|
|
|
|
|
options.type = options.type || "Primary";
|
|
|
|
|
|
|
|
|
|
if (item.ImageTags && item.ImageTags[options.type]) {
|
|
|
|
|
|
|
|
|
|
options.tag = item.ImageTags[options.type];
|
|
|
|
|
return connectionManager.getApiClient(item.ServerId).getScaledImageUrl(item.PrimaryImageItemId || item.Id, options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (options.type === 'Primary') {
|
|
|
|
|
if (item.AlbumId && item.AlbumPrimaryImageTag) {
|
|
|
|
|
|
|
|
|
|
options.tag = item.AlbumPrimaryImageTag;
|
|
|
|
|
return connectionManager.getApiClient(item.ServerId).getScaledImageUrl(item.AlbumId, options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
2018-10-23 01:05:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setPoster(osdPoster, item, secondaryItem) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
|
if (item) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
|
|
var imgUrl = seriesImageUrl(item, { type: 'Primary' }) ||
|
|
|
|
|
seriesImageUrl(item, { type: 'Thumb' }) ||
|
|
|
|
|
imageUrl(item, { type: 'Primary' });
|
|
|
|
|
|
|
|
|
|
if (!imgUrl && secondaryItem) {
|
|
|
|
|
imgUrl = seriesImageUrl(secondaryItem, { type: 'Primary' }) ||
|
|
|
|
|
seriesImageUrl(secondaryItem, { type: 'Thumb' }) ||
|
|
|
|
|
imageUrl(secondaryItem, { type: 'Primary' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (imgUrl) {
|
|
|
|
|
osdPoster.innerHTML = '<img class="upNextDialog-poster-img" src="' + imgUrl + '" />';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
osdPoster.innerHTML = '';
|
2018-10-23 01:05:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getHtml() {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
|
|
html += '<div class="upNextDialog-poster">';
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
html += '<div class="flex flex-direction-column flex-grow">';
|
|
|
|
|
|
|
|
|
|
html += '<h2 class="upNextDialog-nextVideoText" style="margin:.25em 0;"> </h2>';
|
|
|
|
|
|
|
|
|
|
html += '<h3 class="upNextDialog-title" style="margin:.25em 0 .5em;"></h3>';
|
|
|
|
|
|
|
|
|
|
html += '<div class="flex flex-direction-row upNextDialog-mediainfo">';
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
html += '<div class="upNextDialog-overview" style="margin-top:1em;"></div>';
|
|
|
|
|
|
|
|
|
|
html += '<div class="flex flex-direction-row upNextDialog-buttons" style="margin-top:1em;">';
|
|
|
|
|
|
|
|
|
|
html += '<button type="button" is="emby-button" class="raised raised-mini btnStartNow upNextDialog-button">';
|
|
|
|
|
html += globalize.translate('sharedcomponents#HeaderStartNow');
|
|
|
|
|
html += '</button>';
|
|
|
|
|
|
|
|
|
|
html += '<button type="button" is="emby-button" class="raised raised-mini btnHide upNextDialog-button">';
|
|
|
|
|
html += globalize.translate('sharedcomponents#Hide');
|
|
|
|
|
html += '</button>';
|
|
|
|
|
|
|
|
|
|
// buttons
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
// main
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
return html;
|
2018-10-23 01:05:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setNextVideoText() {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
|
|
var instance = this;
|
|
|
|
|
|
|
|
|
|
var elem = instance.options.parent;
|
|
|
|
|
|
|
|
|
|
var secondsRemaining = Math.max(Math.round(getTimeRemainingMs(instance) / 1000), 0);
|
|
|
|
|
|
|
|
|
|
console.log('up next seconds remaining: ' + secondsRemaining);
|
|
|
|
|
|
|
|
|
|
var timeText = '<span class="upNextDialog-countdownText">' + globalize.translate('sharedcomponents#HeaderSecondsValue', secondsRemaining) + '</span>';
|
|
|
|
|
|
|
|
|
|
var nextVideoText = instance.itemType === 'Episode' ?
|
|
|
|
|
globalize.translate('sharedcomponents#HeaderNextEpisodePlayingInValue', timeText) :
|
|
|
|
|
globalize.translate('sharedcomponents#HeaderNextVideoPlayingInValue', timeText);
|
|
|
|
|
|
|
|
|
|
elem.querySelector('.upNextDialog-nextVideoText').innerHTML = nextVideoText;
|
2018-10-23 01:05:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fillItem(item) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
|
|
var instance = this;
|
|
|
|
|
|
|
|
|
|
var elem = instance.options.parent;
|
|
|
|
|
|
|
|
|
|
setPoster(elem.querySelector('.upNextDialog-poster'), item);
|
|
|
|
|
|
|
|
|
|
elem.querySelector('.upNextDialog-overview').innerHTML = item.Overview || '';
|
|
|
|
|
|
|
|
|
|
elem.querySelector('.upNextDialog-mediainfo').innerHTML = mediaInfo.getPrimaryMediaInfoHtml(item, {
|
|
|
|
|
});
|
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
|
var title = itemHelper.getDisplayName(item);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
if (item.SeriesName) {
|
|
|
|
|
title = item.SeriesName + ' - ' + title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
elem.querySelector('.upNextDialog-title').innerHTML = title || '';
|
|
|
|
|
|
|
|
|
|
instance.itemType = item.Type;
|
|
|
|
|
|
|
|
|
|
instance.show();
|
2018-10-23 01:05:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function clearCountdownTextTimeout(instance) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
if (instance._countdownTextTimeout) {
|
|
|
|
|
clearInterval(instance._countdownTextTimeout);
|
|
|
|
|
instance._countdownTextTimeout = null;
|
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onStartNowClick() {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
|
var options = this.options;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
|
if (options) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
|
var player = options.player;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
|
|
this.hide();
|
|
|
|
|
|
|
|
|
|
playbackManager.nextTrack(player);
|
2018-10-23 01:05:09 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function init(instance, options) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
|
|
options.parent.innerHTML = getHtml();
|
|
|
|
|
|
|
|
|
|
options.parent.classList.add('hide');
|
|
|
|
|
options.parent.classList.add('upNextDialog');
|
|
|
|
|
options.parent.classList.add('upNextDialog-hidden');
|
|
|
|
|
|
|
|
|
|
fillItem.call(instance, options.nextItem);
|
|
|
|
|
|
|
|
|
|
options.parent.querySelector('.btnHide').addEventListener('click', instance.hide.bind(instance));
|
|
|
|
|
options.parent.querySelector('.btnStartNow').addEventListener('click', onStartNowClick.bind(instance));
|
2018-10-23 01:05:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function clearHideAnimationEventListeners(instance, elem) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
|
var fn = instance._onHideAnimationComplete;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
|
|
if (fn) {
|
|
|
|
|
dom.removeEventListener(elem, transitionEndEventName, fn, {
|
|
|
|
|
once: true
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onHideAnimationComplete(e) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
|
|
var instance = this;
|
|
|
|
|
var elem = e.target;
|
|
|
|
|
|
|
|
|
|
elem.classList.add('hide');
|
|
|
|
|
|
|
|
|
|
clearHideAnimationEventListeners(instance, elem);
|
|
|
|
|
events.trigger(instance, 'hide');
|
2018-10-23 01:05:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hideComingUpNext() {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
|
var instance = this;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
clearCountdownTextTimeout(this);
|
|
|
|
|
|
|
|
|
|
if (!instance.options) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var elem = instance.options.parent;
|
|
|
|
|
|
|
|
|
|
if (!elem) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clearHideAnimationEventListeners(this, elem);
|
|
|
|
|
|
|
|
|
|
if (elem.classList.contains('upNextDialog-hidden')) {
|
|
|
|
|
return;
|
2018-10-23 01:05:09 +03:00
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
|
|
// trigger a reflow to force it to animate again
|
|
|
|
|
void elem.offsetWidth;
|
|
|
|
|
|
|
|
|
|
elem.classList.add('upNextDialog-hidden');
|
|
|
|
|
|
|
|
|
|
var fn = onHideAnimationComplete.bind(instance);
|
|
|
|
|
instance._onHideAnimationComplete = fn;
|
|
|
|
|
|
|
|
|
|
dom.addEventListener(elem, transitionEndEventName, fn, {
|
|
|
|
|
once: true
|
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getTimeRemainingMs(instance) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
|
var options = instance.options;
|
|
|
|
|
if (options) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
|
var runtimeTicks = playbackManager.duration(options.player);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
|
if (runtimeTicks) {
|
|
|
|
|
var timeRemainingTicks = runtimeTicks - playbackManager.currentTime(options.player);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
|
|
return Math.round(timeRemainingTicks / 10000);
|
2018-10-23 01:05:09 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
|
|
return 0;
|
2018-10-23 01:05:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function startComingUpNextHideTimer(instance) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
|
|
var timeRemainingMs = getTimeRemainingMs(instance);
|
|
|
|
|
|
|
|
|
|
if (timeRemainingMs <= 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setNextVideoText.call(instance);
|
|
|
|
|
clearCountdownTextTimeout(instance);
|
|
|
|
|
|
|
|
|
|
instance._countdownTextTimeout = setInterval(setNextVideoText.bind(instance), 400);
|
2018-10-23 01:05:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function UpNextDialog(options) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
|
|
this.options = options;
|
|
|
|
|
|
|
|
|
|
init(this, options);
|
2018-10-23 01:05:09 +03:00
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
|
|
UpNextDialog.prototype.show = function () {
|
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
|
var elem = this.options.parent;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
|
|
clearHideAnimationEventListeners(this, elem);
|
|
|
|
|
|
|
|
|
|
elem.classList.remove('hide');
|
|
|
|
|
|
|
|
|
|
// trigger a reflow to force it to animate again
|
|
|
|
|
void elem.offsetWidth;
|
|
|
|
|
|
|
|
|
|
elem.classList.remove('upNextDialog-hidden');
|
|
|
|
|
|
|
|
|
|
if (layoutManager.tv) {
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
focusManager.focus(elem.querySelector('.btnStartNow'));
|
|
|
|
|
}, 50);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
startComingUpNextHideTimer(this);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UpNextDialog.prototype.hide = function () {
|
|
|
|
|
|
|
|
|
|
hideComingUpNext.call(this);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UpNextDialog.prototype.destroy = function () {
|
|
|
|
|
|
|
|
|
|
hideComingUpNext.call(this);
|
|
|
|
|
|
|
|
|
|
this.options = null;
|
|
|
|
|
this.itemType = null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return UpNextDialog;
|
2018-10-23 01:05:09 +03:00
|
|
|
|
});
|