|
|
|
|
@@ -611,7 +611,8 @@ const SlideUtils = {
|
|
|
|
|
if (!container) {
|
|
|
|
|
container = this.createElement("div", {
|
|
|
|
|
id: "slides-container",
|
|
|
|
|
className: "noautofocus"
|
|
|
|
|
className: "noautofocus",
|
|
|
|
|
tabIndex: "-1"
|
|
|
|
|
});
|
|
|
|
|
document.body.appendChild(container);
|
|
|
|
|
}
|
|
|
|
|
@@ -742,7 +743,9 @@ const SlideUtils = {
|
|
|
|
|
iv_load_policy: 3,
|
|
|
|
|
rel: 0,
|
|
|
|
|
playsinline: 1,
|
|
|
|
|
origin: window.location.origin
|
|
|
|
|
origin: window.location.origin,
|
|
|
|
|
widget_referrer: window.location.href,
|
|
|
|
|
enablejsapi: 1
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
@@ -1338,7 +1341,7 @@ const ApiUtils = {
|
|
|
|
|
/**
|
|
|
|
|
* Fetches the first local trailer for an item
|
|
|
|
|
* @param {string} itemId - Item ID
|
|
|
|
|
* @returns {Promise<string|null>} Stream URL or null
|
|
|
|
|
* @returns {Promise<Object|null>} Trailer data object {id, url} or null
|
|
|
|
|
*/
|
|
|
|
|
async fetchLocalTrailer(itemId) {
|
|
|
|
|
try {
|
|
|
|
|
@@ -1358,8 +1361,11 @@ const ApiUtils = {
|
|
|
|
|
const trailer = trailers[0];
|
|
|
|
|
const mediaSourceId = trailer.MediaSources && trailer.MediaSources[0] ? trailer.MediaSources[0].Id : trailer.Id;
|
|
|
|
|
|
|
|
|
|
// Construct stream URL
|
|
|
|
|
return `${STATE.jellyfinData.serverAddress}/Videos/${trailer.Id}/stream.mp4?Static=true&mediaSourceId=${mediaSourceId}&api_key=${STATE.jellyfinData.accessToken}`;
|
|
|
|
|
// Return object with ID and URL
|
|
|
|
|
return {
|
|
|
|
|
id: trailer.Id,
|
|
|
|
|
url: `${STATE.jellyfinData.serverAddress}/Videos/${trailer.Id}/stream.mp4?Static=true&mediaSourceId=${mediaSourceId}&api_key=${STATE.jellyfinData.accessToken}`
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
@@ -1427,16 +1433,19 @@ const VisibilityObserver = {
|
|
|
|
|
|
|
|
|
|
// If a full screen video player is active, hide slideshow and stop playback
|
|
|
|
|
if ((videoPlayer && !videoPlayer.classList.contains('hide')) || (trailerPlayer && !trailerPlayer.classList.contains('hide'))) {
|
|
|
|
|
const container = document.getElementById("slides-container");
|
|
|
|
|
if (container) {
|
|
|
|
|
container.style.display = "none";
|
|
|
|
|
container.style.visibility = "hidden";
|
|
|
|
|
container.style.pointerEvents = "none";
|
|
|
|
|
if (this._lastVisibleState !== 'player-active') {
|
|
|
|
|
this._lastVisibleState = 'player-active';
|
|
|
|
|
const container = document.getElementById("slides-container");
|
|
|
|
|
if (container) {
|
|
|
|
|
container.style.display = "none";
|
|
|
|
|
container.style.visibility = "hidden";
|
|
|
|
|
container.style.pointerEvents = "none";
|
|
|
|
|
}
|
|
|
|
|
if (STATE.slideshow.slideInterval) {
|
|
|
|
|
STATE.slideshow.slideInterval.stop();
|
|
|
|
|
}
|
|
|
|
|
SlideshowManager.stopAllPlayback();
|
|
|
|
|
}
|
|
|
|
|
if (STATE.slideshow.slideInterval) {
|
|
|
|
|
STATE.slideshow.slideInterval.stop();
|
|
|
|
|
}
|
|
|
|
|
SlideshowManager.stopAllPlayback();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1451,20 +1460,27 @@ const VisibilityObserver = {
|
|
|
|
|
activeTab &&
|
|
|
|
|
activeTab.getAttribute("data-index") === "0";
|
|
|
|
|
|
|
|
|
|
container.style.display = isVisible ? "block" : "none";
|
|
|
|
|
container.style.visibility = isVisible ? "visible" : "hidden";
|
|
|
|
|
container.style.pointerEvents = isVisible ? "auto" : "none";
|
|
|
|
|
const newState = isVisible ? 'visible' : 'hidden';
|
|
|
|
|
|
|
|
|
|
if (isVisible) {
|
|
|
|
|
if (STATE.slideshow.slideInterval && !STATE.slideshow.isPaused) {
|
|
|
|
|
STATE.slideshow.slideInterval.start();
|
|
|
|
|
SlideshowManager.resumeActivePlayback();
|
|
|
|
|
// Only update DOM and trigger actions when state actually changes
|
|
|
|
|
if (this._lastVisibleState !== newState) {
|
|
|
|
|
this._lastVisibleState = newState;
|
|
|
|
|
|
|
|
|
|
container.style.display = isVisible ? "block" : "none";
|
|
|
|
|
container.style.visibility = isVisible ? "visible" : "hidden";
|
|
|
|
|
container.style.pointerEvents = isVisible ? "auto" : "none";
|
|
|
|
|
|
|
|
|
|
if (isVisible) {
|
|
|
|
|
if (STATE.slideshow.slideInterval && !STATE.slideshow.isPaused) {
|
|
|
|
|
STATE.slideshow.slideInterval.start();
|
|
|
|
|
SlideshowManager.resumeActivePlayback();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (STATE.slideshow.slideInterval) {
|
|
|
|
|
STATE.slideshow.slideInterval.stop();
|
|
|
|
|
}
|
|
|
|
|
SlideshowManager.stopAllPlayback();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (STATE.slideshow.slideInterval) {
|
|
|
|
|
STATE.slideshow.slideInterval.stop();
|
|
|
|
|
}
|
|
|
|
|
SlideshowManager.stopAllPlayback();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
@@ -1472,7 +1488,13 @@ const VisibilityObserver = {
|
|
|
|
|
* Initializes visibility observer
|
|
|
|
|
*/
|
|
|
|
|
init() {
|
|
|
|
|
const observer = new MutationObserver(() => this.updateVisibility());
|
|
|
|
|
// MARK: Mark
|
|
|
|
|
// const observer = new MutationObserver(() => this.updateVisibility());
|
|
|
|
|
let debounceTimer = null;
|
|
|
|
|
const observer = new MutationObserver(() => {
|
|
|
|
|
if (debounceTimer) clearTimeout(debounceTimer);
|
|
|
|
|
debounceTimer = setTimeout(() => this.updateVisibility(), 250);
|
|
|
|
|
});
|
|
|
|
|
observer.observe(document.body, { childList: true, subtree: true });
|
|
|
|
|
|
|
|
|
|
document.body.addEventListener("click", () => this.updateVisibility());
|
|
|
|
|
@@ -1571,8 +1593,24 @@ const SlideCreator = {
|
|
|
|
|
|
|
|
|
|
// 1a. Custom URL override
|
|
|
|
|
if (STATE.slideshow.customTrailerUrls && STATE.slideshow.customTrailerUrls[itemId]) {
|
|
|
|
|
trailerUrl = STATE.slideshow.customTrailerUrls[itemId];
|
|
|
|
|
console.log(`Using custom trailer URL for ${itemId}: ${trailerUrl}`);
|
|
|
|
|
const customValue = STATE.slideshow.customTrailerUrls[itemId];
|
|
|
|
|
|
|
|
|
|
// Check if the custom value is a Jellyfin Item ID (GUID)
|
|
|
|
|
const guidMatch = customValue.match(/^([0-9a-f]{32})$/i);
|
|
|
|
|
|
|
|
|
|
if (guidMatch) {
|
|
|
|
|
const videoId = guidMatch[1];
|
|
|
|
|
console.log(`Using custom local video ID for ${itemId}: ${videoId}`);
|
|
|
|
|
|
|
|
|
|
trailerUrl = {
|
|
|
|
|
id: videoId,
|
|
|
|
|
url: `${STATE.jellyfinData.serverAddress}/Videos/${videoId}/stream.mp4?Static=true&api_key=${STATE.jellyfinData.accessToken}`
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
// Assume it's a standard URL (YouTube, etc.)
|
|
|
|
|
trailerUrl = customValue;
|
|
|
|
|
console.log(`Using custom trailer URL for ${itemId}: ${trailerUrl}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 1b. Check Local Trailer if preferred
|
|
|
|
|
else if (CONFIG.preferLocalTrailers && item.LocalTrailerCount > 0 && item.localTrailerUrl) {
|
|
|
|
|
@@ -1597,12 +1635,17 @@ const SlideCreator = {
|
|
|
|
|
let videoId = null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const urlObj = new URL(trailerUrl);
|
|
|
|
|
if (urlObj.hostname.includes('youtube.com') || urlObj.hostname.includes('youtu.be')) {
|
|
|
|
|
let urlToCheck = trailerUrl;
|
|
|
|
|
if (typeof trailerUrl === 'object' && trailerUrl.url) {
|
|
|
|
|
urlToCheck = trailerUrl.url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const urlObjChecked = new URL(urlToCheck);
|
|
|
|
|
if (urlObjChecked.hostname.includes('youtube.com') || urlObjChecked.hostname.includes('youtu.be')) {
|
|
|
|
|
isYoutube = true;
|
|
|
|
|
videoId = urlObj.searchParams.get('v');
|
|
|
|
|
if (!videoId && urlObj.hostname.includes('youtu.be')) {
|
|
|
|
|
videoId = urlObj.pathname.substring(1);
|
|
|
|
|
videoId = urlObjChecked.searchParams.get('v');
|
|
|
|
|
if (!videoId && urlObjChecked.hostname.includes('youtu.be')) {
|
|
|
|
|
videoId = urlObjChecked.pathname.substring(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
@@ -1633,7 +1676,9 @@ const SlideCreator = {
|
|
|
|
|
rel: 0,
|
|
|
|
|
loop: 0,
|
|
|
|
|
playsinline: 1,
|
|
|
|
|
origin: window.location.origin
|
|
|
|
|
origin: window.location.origin,
|
|
|
|
|
widget_referrer: window.location.href,
|
|
|
|
|
enablejsapi: 1
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Determine video quality
|
|
|
|
|
@@ -1668,6 +1713,13 @@ const SlideCreator = {
|
|
|
|
|
playerVars: playerVars,
|
|
|
|
|
events: {
|
|
|
|
|
'onReady': (event) => {
|
|
|
|
|
// Prevent iframe from stealing focus (critical for TV mode)
|
|
|
|
|
const iframe = event.target.getIframe();
|
|
|
|
|
if (iframe) {
|
|
|
|
|
iframe.setAttribute('tabindex', '-1');
|
|
|
|
|
iframe.setAttribute('inert', '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Store start/end time and videoId for later use
|
|
|
|
|
event.target._startTime = playerVars.start || 0;
|
|
|
|
|
event.target._endTime = playerVars.end || undefined;
|
|
|
|
|
@@ -1684,11 +1736,18 @@ const SlideCreator = {
|
|
|
|
|
event.target.setPlaybackQuality(quality);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Only play if this is the active slide
|
|
|
|
|
// Only play if this is the active slide AND the slideshow is visible
|
|
|
|
|
const slide = document.querySelector(`.slide[data-item-id="${itemId}"]`);
|
|
|
|
|
const isVideoPlayerOpen = document.querySelector('.videoPlayerContainer') || document.querySelector('.youtubePlayerContainer');
|
|
|
|
|
|
|
|
|
|
if (slide && slide.classList.contains('active') && !document.hidden && (!isVideoPlayerOpen || isVideoPlayerOpen.classList.contains('hide'))) {
|
|
|
|
|
const currentIndex = STATE.slideshow.currentSlideIndex;
|
|
|
|
|
const currentItemId = STATE.slideshow.itemIds[currentIndex];
|
|
|
|
|
if (currentItemId !== itemId) {
|
|
|
|
|
console.log(`Slide ${itemId} is no longer active (current: ${currentItemId}), aborting playback.`);
|
|
|
|
|
event.target.mute(); // Mute just in case
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
event.target.playVideo();
|
|
|
|
|
|
|
|
|
|
// Check if it actually started playing after a short delay (handling autoplay blocks)
|
|
|
|
|
@@ -1729,7 +1788,8 @@ const SlideCreator = {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
'onError': () => {
|
|
|
|
|
'onError': (event) => {
|
|
|
|
|
console.warn(`YouTube player error ${event.data} for video ${videoId}`);
|
|
|
|
|
// Fallback to next slide on error
|
|
|
|
|
if (CONFIG.waitForTrailerToEnd) {
|
|
|
|
|
SlideshowManager.nextSlide();
|
|
|
|
|
@@ -1746,7 +1806,7 @@ const SlideCreator = {
|
|
|
|
|
|
|
|
|
|
const videoAttributes = {
|
|
|
|
|
className: "backdrop video-backdrop",
|
|
|
|
|
src: trailerUrl,
|
|
|
|
|
src: (typeof trailerUrl === 'object' ? trailerUrl.url : trailerUrl),
|
|
|
|
|
autoplay: false,
|
|
|
|
|
preload: "auto",
|
|
|
|
|
loop: false,
|
|
|
|
|
@@ -1765,7 +1825,18 @@ const SlideCreator = {
|
|
|
|
|
|
|
|
|
|
STATE.slideshow.videoPlayers[itemId] = backdrop;
|
|
|
|
|
|
|
|
|
|
backdrop.addEventListener('play', () => {
|
|
|
|
|
backdrop.addEventListener('play', (event) => {
|
|
|
|
|
const slide = document.querySelector(`.slide[data-item-id="${itemId}"]`);
|
|
|
|
|
const currentIndex = STATE.slideshow.currentSlideIndex;
|
|
|
|
|
const currentItemId = STATE.slideshow.itemIds[currentIndex];
|
|
|
|
|
|
|
|
|
|
if (!slide || !slide.classList.contains('active') || currentItemId !== itemId) {
|
|
|
|
|
console.log(`Local video ${itemId} started playing but is not active, pausing.`);
|
|
|
|
|
event.target.pause();
|
|
|
|
|
event.target.currentTime = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CONFIG.waitForTrailerToEnd && STATE.slideshow.slideInterval) {
|
|
|
|
|
STATE.slideshow.slideInterval.stop();
|
|
|
|
|
}
|
|
|
|
|
@@ -2037,11 +2108,20 @@ const SlideCreator = {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a trailer button
|
|
|
|
|
* @param {string} url - Trailer URL
|
|
|
|
|
* @param {string|Object} trailerInfo - Trailer URL string or object {id, url}
|
|
|
|
|
* @returns {HTMLElement} Trailer button element
|
|
|
|
|
*/
|
|
|
|
|
createTrailerButton(url) {
|
|
|
|
|
createTrailerButton(trailerInfo) {
|
|
|
|
|
const trailerText = LocalizationUtils.getLocalizedString('Trailer', 'Trailer');
|
|
|
|
|
|
|
|
|
|
let url = trailerInfo;
|
|
|
|
|
let localTrailerId = null;
|
|
|
|
|
|
|
|
|
|
if (typeof trailerInfo === 'object' && trailerInfo !== null) {
|
|
|
|
|
url = trailerInfo.url;
|
|
|
|
|
localTrailerId = trailerInfo.id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SlideUtils.createElement("button", {
|
|
|
|
|
className: "detailButton trailer-button",
|
|
|
|
|
innerHTML: `<span class="material-icons">movie</span> <span class="trailer-text">${trailerText}</span>`,
|
|
|
|
|
@@ -2049,7 +2129,13 @@ const SlideCreator = {
|
|
|
|
|
onclick: (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
SlideUtils.openVideoModal(url);
|
|
|
|
|
|
|
|
|
|
if (localTrailerId) {
|
|
|
|
|
// Play local trailer using native player
|
|
|
|
|
ApiUtils.playItem(localTrailerId);
|
|
|
|
|
} else {
|
|
|
|
|
SlideUtils.openVideoModal(url);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
@@ -2194,6 +2280,16 @@ const SlideshowManager = {
|
|
|
|
|
let previousVisibleSlide;
|
|
|
|
|
try {
|
|
|
|
|
const container = SlideUtils.getOrCreateSlidesContainer();
|
|
|
|
|
|
|
|
|
|
const activeElement = document.activeElement;
|
|
|
|
|
let focusSelector = null;
|
|
|
|
|
if (container.contains(activeElement)) {
|
|
|
|
|
if (activeElement.classList.contains('play-button')) focusSelector = '.play-button';
|
|
|
|
|
else if (activeElement.classList.contains('detail-button')) focusSelector = '.detail-button';
|
|
|
|
|
else if (activeElement.classList.contains('favorite-button')) focusSelector = '.favorite-button';
|
|
|
|
|
else if (activeElement.classList.contains('trailer-button')) focusSelector = '.trailer-button';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const totalItems = STATE.slideshow.totalItems;
|
|
|
|
|
|
|
|
|
|
index = Math.max(0, Math.min(index, totalItems - 1));
|
|
|
|
|
@@ -2222,91 +2318,27 @@ const SlideshowManager = {
|
|
|
|
|
|
|
|
|
|
currentSlide.classList.add("active");
|
|
|
|
|
|
|
|
|
|
// Manage Video Playback: Stop others, Play current
|
|
|
|
|
|
|
|
|
|
// 1. Pause all other YouTube players
|
|
|
|
|
if (STATE.slideshow.videoPlayers) {
|
|
|
|
|
Object.keys(STATE.slideshow.videoPlayers).forEach(id => {
|
|
|
|
|
if (id !== currentItemId) {
|
|
|
|
|
const p = STATE.slideshow.videoPlayers[id];
|
|
|
|
|
if (p && typeof p.pauseVideo === 'function') {
|
|
|
|
|
p.pauseVideo();
|
|
|
|
|
}
|
|
|
|
|
// Restore focus for TV mode navigation continuity
|
|
|
|
|
requestAnimationFrame(() => {
|
|
|
|
|
if (focusSelector) {
|
|
|
|
|
const target = currentSlide.querySelector(focusSelector);
|
|
|
|
|
if (target) {
|
|
|
|
|
target.focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. Pause all other HTML5 videos e.g. local trailers
|
|
|
|
|
document.querySelectorAll('video').forEach(video => {
|
|
|
|
|
if (!video.closest(`.slide[data-item-id="${currentItemId}"]`)) {
|
|
|
|
|
video.pause();
|
|
|
|
|
}
|
|
|
|
|
// Always ensure container has focus in TV mode to keep keyboard navigation working
|
|
|
|
|
const isTvMode = (window.layoutManager && window.layoutManager.tv) ||
|
|
|
|
|
document.documentElement.classList.contains('layout-tv') ||
|
|
|
|
|
document.body.classList.contains('layout-tv');
|
|
|
|
|
if (isTvMode) {
|
|
|
|
|
container.focus({ preventScroll: true });
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 3. Play and Reset current video
|
|
|
|
|
const videoBackdrop = currentSlide.querySelector('.video-backdrop');
|
|
|
|
|
|
|
|
|
|
// Update mute button visibility
|
|
|
|
|
const muteButton = document.querySelector('.mute-button');
|
|
|
|
|
if (muteButton) {
|
|
|
|
|
const hasVideo = !!videoBackdrop;
|
|
|
|
|
muteButton.style.display = hasVideo ? 'block' : 'none';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (videoBackdrop) {
|
|
|
|
|
if (videoBackdrop.tagName === 'VIDEO') {
|
|
|
|
|
videoBackdrop.currentTime = 0;
|
|
|
|
|
|
|
|
|
|
videoBackdrop.muted = STATE.slideshow.isMuted;
|
|
|
|
|
if (!STATE.slideshow.isMuted) {
|
|
|
|
|
videoBackdrop.volume = 0.4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
videoBackdrop.play().catch(e => {
|
|
|
|
|
// Check if it actually started playing after a short delay (handling autoplay blocks)
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
if (videoBackdrop.paused) {
|
|
|
|
|
console.warn(`Autoplay blocked for ${itemId}, attempting muted fallback`);
|
|
|
|
|
videoBackdrop.muted = true;
|
|
|
|
|
videoBackdrop.play().catch(err => console.error("Muted fallback failed", err));
|
|
|
|
|
}
|
|
|
|
|
}, 1000);
|
|
|
|
|
});
|
|
|
|
|
} else if (STATE.slideshow.videoPlayers && STATE.slideshow.videoPlayers[currentItemId]) {
|
|
|
|
|
const player = STATE.slideshow.videoPlayers[currentItemId];
|
|
|
|
|
if (player && typeof player.loadVideoById === 'function' && player._videoId) {
|
|
|
|
|
// Use loadVideoById to enforce start and end times
|
|
|
|
|
player.loadVideoById({
|
|
|
|
|
videoId: player._videoId,
|
|
|
|
|
startSeconds: player._startTime || 0,
|
|
|
|
|
endSeconds: player._endTime
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (STATE.slideshow.isMuted) {
|
|
|
|
|
player.mute();
|
|
|
|
|
} else {
|
|
|
|
|
player.unMute();
|
|
|
|
|
player.setVolume(40);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if playback successfully started, otherwise fallback to muted
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
if (player.getPlayerState &&
|
|
|
|
|
player.getPlayerState() !== YT.PlayerState.PLAYING &&
|
|
|
|
|
player.getPlayerState() !== YT.PlayerState.BUFFERING) {
|
|
|
|
|
console.log("YouTube loadVideoById didn't start playback, retrying muted...");
|
|
|
|
|
player.mute();
|
|
|
|
|
player.playVideo();
|
|
|
|
|
}
|
|
|
|
|
}, 1000);
|
|
|
|
|
} else if (player && typeof player.seekTo === 'function') {
|
|
|
|
|
// Fallback if loadVideoById is not available or videoId missing
|
|
|
|
|
const startTime = player._startTime || 0;
|
|
|
|
|
player.seekTo(startTime);
|
|
|
|
|
player.playVideo();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Manage Video Playback: Stop others, Play current
|
|
|
|
|
this.pauseOtherVideos(currentItemId);
|
|
|
|
|
this.playCurrentVideo(currentSlide, currentItemId);
|
|
|
|
|
|
|
|
|
|
const enableAnimations = MediaBarEnhancedSettingsManager.getSetting('slideAnimations', CONFIG.slideAnimationEnabled);
|
|
|
|
|
|
|
|
|
|
@@ -2315,7 +2347,8 @@ const SlideshowManager = {
|
|
|
|
|
if (backdrop && !backdrop.classList.contains("video-backdrop")) {
|
|
|
|
|
backdrop.classList.add("animate");
|
|
|
|
|
}
|
|
|
|
|
currentSlide.querySelector(".logo").classList.add("animate");
|
|
|
|
|
const logo = currentSlide.querySelector(".logo");
|
|
|
|
|
if (logo) logo.classList.add("animate");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
STATE.slideshow.currentSlideIndex = index;
|
|
|
|
|
@@ -2398,18 +2431,20 @@ const SlideshowManager = {
|
|
|
|
|
*/
|
|
|
|
|
async preloadAdjacentSlides(currentIndex) {
|
|
|
|
|
const totalItems = STATE.slideshow.totalItems;
|
|
|
|
|
const preloadCount = CONFIG.preloadCount;
|
|
|
|
|
const preloadCount = Math.min(Math.max(CONFIG.preloadCount || 1, 1), 5);
|
|
|
|
|
|
|
|
|
|
const nextIndex = (currentIndex + 1) % totalItems;
|
|
|
|
|
const itemId = STATE.slideshow.itemIds[nextIndex];
|
|
|
|
|
// Preload next slides
|
|
|
|
|
for (let i = 1; i <= preloadCount; i++) {
|
|
|
|
|
const nextIndex = (currentIndex + i) % totalItems;
|
|
|
|
|
const itemId = STATE.slideshow.itemIds[nextIndex];
|
|
|
|
|
SlideCreator.createSlideForItemId(itemId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await SlideCreator.createSlideForItemId(itemId);
|
|
|
|
|
|
|
|
|
|
if (preloadCount > 1) {
|
|
|
|
|
const prevIndex = (currentIndex - 1 + totalItems) % totalItems;
|
|
|
|
|
const prevItemId = STATE.slideshow.itemIds[prevIndex];
|
|
|
|
|
|
|
|
|
|
SlideCreator.createSlideForItemId(prevItemId);
|
|
|
|
|
// Preload previous slides
|
|
|
|
|
for (let i = 1; i <= preloadCount; i++) {
|
|
|
|
|
const prevIndex = (currentIndex - i + totalItems) % totalItems;
|
|
|
|
|
const prevItemId = STATE.slideshow.itemIds[prevIndex];
|
|
|
|
|
SlideCreator.createSlideForItemId(prevItemId);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
@@ -2438,12 +2473,20 @@ const SlideshowManager = {
|
|
|
|
|
pruneSlideCache() {
|
|
|
|
|
const currentIndex = STATE.slideshow.currentSlideIndex;
|
|
|
|
|
const keepRange = 5;
|
|
|
|
|
let prunedAny = false;
|
|
|
|
|
|
|
|
|
|
Object.keys(STATE.slideshow.createdSlides).forEach((itemId) => {
|
|
|
|
|
const index = STATE.slideshow.itemIds.indexOf(itemId);
|
|
|
|
|
if (index === -1) return;
|
|
|
|
|
|
|
|
|
|
const distance = Math.abs(index - currentIndex);
|
|
|
|
|
const totalItems = STATE.slideshow.itemIds.length;
|
|
|
|
|
|
|
|
|
|
// Calculate wrapped distance
|
|
|
|
|
let distance = Math.abs(index - currentIndex);
|
|
|
|
|
if (totalItems > keepRange * 2) {
|
|
|
|
|
distance = Math.min(distance, totalItems - distance);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (distance > keepRange) {
|
|
|
|
|
// Destroy video player if exists
|
|
|
|
|
if (STATE.slideshow.videoPlayers[itemId]) {
|
|
|
|
|
@@ -2462,10 +2505,27 @@ const SlideshowManager = {
|
|
|
|
|
if (slide) slide.remove();
|
|
|
|
|
|
|
|
|
|
delete STATE.slideshow.createdSlides[itemId];
|
|
|
|
|
prunedAny = true;
|
|
|
|
|
|
|
|
|
|
console.log(`Pruned slide ${itemId} at distance ${distance} from view`);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// After pruning, restore focus to container in TV mode
|
|
|
|
|
if (prunedAny) {
|
|
|
|
|
const isTvMode = (window.layoutManager && window.layoutManager.tv) ||
|
|
|
|
|
document.documentElement.classList.contains('layout-tv') ||
|
|
|
|
|
document.body.classList.contains('layout-tv');
|
|
|
|
|
if (isTvMode) {
|
|
|
|
|
// Use setTimeout to execute AFTER Jellyfin's focus manager processes the iframe removal
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
const container = document.getElementById("slides-container");
|
|
|
|
|
if (container && container.style.display !== 'none') {
|
|
|
|
|
container.focus({ preventScroll: true });
|
|
|
|
|
}
|
|
|
|
|
}, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
toggleMute() {
|
|
|
|
|
@@ -2584,6 +2644,114 @@ const SlideshowManager = {
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Pauses all video players except the one with the given item ID
|
|
|
|
|
* @param {string} excludeItemId - Item ID to exclude from pausing
|
|
|
|
|
*/
|
|
|
|
|
pauseOtherVideos(excludeItemId) {
|
|
|
|
|
// Pause YouTube players
|
|
|
|
|
if (STATE.slideshow.videoPlayers) {
|
|
|
|
|
Object.keys(STATE.slideshow.videoPlayers).forEach(id => {
|
|
|
|
|
if (id !== excludeItemId) {
|
|
|
|
|
const p = STATE.slideshow.videoPlayers[id];
|
|
|
|
|
if (p) {
|
|
|
|
|
try {
|
|
|
|
|
if (typeof p.pauseVideo === 'function') {
|
|
|
|
|
p.pauseVideo();
|
|
|
|
|
if (typeof p.mute === 'function') {
|
|
|
|
|
p.mute();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (p.tagName === 'VIDEO') {
|
|
|
|
|
p.pause();
|
|
|
|
|
p.muted = true;
|
|
|
|
|
}
|
|
|
|
|
} catch (e) { console.warn("Error pausing player", id, e); }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// Pause HTML5 videos
|
|
|
|
|
document.querySelectorAll('video').forEach(video => {
|
|
|
|
|
const slideParent = video.closest('.slide');
|
|
|
|
|
if (slideParent && slideParent.dataset.itemId !== excludeItemId) {
|
|
|
|
|
try {
|
|
|
|
|
video.pause();
|
|
|
|
|
video.muted = true;
|
|
|
|
|
} catch (e) {}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Plays the video backdrop on the given slide and updates mute button visibility
|
|
|
|
|
* @param {Element} slide - The slide DOM element
|
|
|
|
|
* @param {string} itemId - The item ID of the slide
|
|
|
|
|
* @returns {boolean} Whether a video was found and playback attempted
|
|
|
|
|
*/
|
|
|
|
|
playCurrentVideo(slide, itemId) {
|
|
|
|
|
const videoBackdrop = slide.querySelector('.video-backdrop');
|
|
|
|
|
|
|
|
|
|
// Update mute button visibility
|
|
|
|
|
const muteButton = document.querySelector('.mute-button');
|
|
|
|
|
if (muteButton) {
|
|
|
|
|
muteButton.style.display = videoBackdrop ? 'block' : 'none';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!videoBackdrop) return false;
|
|
|
|
|
|
|
|
|
|
if (videoBackdrop.tagName === 'VIDEO') {
|
|
|
|
|
videoBackdrop.currentTime = 0;
|
|
|
|
|
videoBackdrop.muted = STATE.slideshow.isMuted;
|
|
|
|
|
if (!STATE.slideshow.isMuted) videoBackdrop.volume = 0.4;
|
|
|
|
|
|
|
|
|
|
videoBackdrop.play().catch(() => {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
if (videoBackdrop.paused) {
|
|
|
|
|
console.warn(`Autoplay blocked for ${itemId}, attempting muted fallback`);
|
|
|
|
|
videoBackdrop.muted = true;
|
|
|
|
|
videoBackdrop.play().catch(err => console.error("Muted fallback failed", err));
|
|
|
|
|
}
|
|
|
|
|
}, 1000);
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// YouTube player
|
|
|
|
|
const player = STATE.slideshow.videoPlayers?.[itemId];
|
|
|
|
|
if (player && typeof player.loadVideoById === 'function' && player._videoId) {
|
|
|
|
|
player.loadVideoById({
|
|
|
|
|
videoId: player._videoId,
|
|
|
|
|
startSeconds: player._startTime || 0,
|
|
|
|
|
endSeconds: player._endTime
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (STATE.slideshow.isMuted) {
|
|
|
|
|
player.mute();
|
|
|
|
|
} else {
|
|
|
|
|
player.unMute();
|
|
|
|
|
player.setVolume(40);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
if (player.getPlayerState &&
|
|
|
|
|
player.getPlayerState() !== YT.PlayerState.PLAYING &&
|
|
|
|
|
player.getPlayerState() !== YT.PlayerState.BUFFERING) {
|
|
|
|
|
console.log("YouTube loadVideoById didn't start playback, retrying muted...");
|
|
|
|
|
player.mute();
|
|
|
|
|
player.playVideo();
|
|
|
|
|
}
|
|
|
|
|
}, 1000);
|
|
|
|
|
return true;
|
|
|
|
|
} else if (player && typeof player.seekTo === 'function') {
|
|
|
|
|
player.seekTo(player._startTime || 0);
|
|
|
|
|
player.playVideo();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Stops all video playback (YouTube and HTML5)
|
|
|
|
|
* Used when navigating away from the home screen
|
|
|
|
|
@@ -2613,14 +2781,16 @@ const SlideshowManager = {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. Pause all HTML5 videos
|
|
|
|
|
// 2. Stop and mute all HTML5 videos
|
|
|
|
|
const container = document.getElementById("slides-container");
|
|
|
|
|
if (container) {
|
|
|
|
|
container.querySelectorAll('video').forEach(video => {
|
|
|
|
|
try {
|
|
|
|
|
video.pause();
|
|
|
|
|
video.muted = true;
|
|
|
|
|
video.currentTime = 0;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.warn("Error pausing HTML5 video:", e);
|
|
|
|
|
console.warn("Error stopping HTML5 video:", e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
@@ -2638,18 +2808,24 @@ const SlideshowManager = {
|
|
|
|
|
const currentSlide = document.querySelector(`.slide[data-item-id="${currentItemId}"]`);
|
|
|
|
|
if (!currentSlide) return;
|
|
|
|
|
|
|
|
|
|
// 1. Try YouTube Player
|
|
|
|
|
const ytPlayer = STATE.slideshow.videoPlayers[currentItemId];
|
|
|
|
|
// YouTube player: just resume, don't reload
|
|
|
|
|
const ytPlayer = STATE.slideshow.videoPlayers?.[currentItemId];
|
|
|
|
|
if (ytPlayer && typeof ytPlayer.playVideo === 'function') {
|
|
|
|
|
if (STATE.slideshow.isMuted) {
|
|
|
|
|
if (typeof ytPlayer.mute === 'function') ytPlayer.mute();
|
|
|
|
|
} else {
|
|
|
|
|
if (typeof ytPlayer.unMute === 'function') ytPlayer.unMute();
|
|
|
|
|
if (typeof ytPlayer.setVolume === 'function') ytPlayer.setVolume(40);
|
|
|
|
|
}
|
|
|
|
|
ytPlayer.playVideo();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. Try HTML5 Video
|
|
|
|
|
const html5Video = currentSlide.querySelector('video');
|
|
|
|
|
// HTML5 video: just resume, don't reset currentTime
|
|
|
|
|
const html5Video = currentSlide.querySelector('video.video-backdrop');
|
|
|
|
|
if (html5Video) {
|
|
|
|
|
if (STATE.slideshow.isMuted) {
|
|
|
|
|
html5Video.muted = true;
|
|
|
|
|
}
|
|
|
|
|
html5Video.muted = STATE.slideshow.isMuted;
|
|
|
|
|
if (!STATE.slideshow.isMuted) html5Video.volume = 0.4;
|
|
|
|
|
html5Video.play().catch(e => console.warn("Error resuming HTML5 video:", e));
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
@@ -2724,7 +2900,7 @@ const SlideshowManager = {
|
|
|
|
|
// Determine if we should handle navigation keys (Arrows, Space, M)
|
|
|
|
|
// TV Mode: Strict focus required (must be on slideshow)
|
|
|
|
|
// Desktop Mode: Loose focus allowed (slideshow OR body/nothing focused)
|
|
|
|
|
const canControlSlideshow = isTvMode ? hasDirectFocus : (hasDirectFocus || isBodyFocused);
|
|
|
|
|
let canControlSlideshow = isTvMode ? hasDirectFocus : (hasDirectFocus || isBodyFocused);
|
|
|
|
|
|
|
|
|
|
// Check for Input Fields (always ignore typing)
|
|
|
|
|
const isInputElement = activeElement && (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA' || activeElement.isContentEditable);
|
|
|
|
|
@@ -2942,7 +3118,7 @@ const SlideshowManager = {
|
|
|
|
|
finalIds.push(id);
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.warn(`Error resolving item ${id}:`, e);
|
|
|
|
|
console.warn(`Error resolving item ${rawId}:`, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return finalIds;
|
|
|
|
|
@@ -3340,75 +3516,25 @@ const MediaBarEnhancedSettingsManager = {
|
|
|
|
|
* Initialize page visibility handling to pause when tab is inactive
|
|
|
|
|
*/
|
|
|
|
|
const initPageVisibilityHandler = () => {
|
|
|
|
|
let wasVideoPlayingBeforeHide = false;
|
|
|
|
|
|
|
|
|
|
document.addEventListener("visibilitychange", () => {
|
|
|
|
|
if (document.hidden) {
|
|
|
|
|
console.log("Tab inactive - pausing slideshow and videos");
|
|
|
|
|
wasVideoPlayingBeforeHide = STATE.slideshow.isVideoPlaying;
|
|
|
|
|
|
|
|
|
|
console.log("Tab inactive - stopping all slideshow playback");
|
|
|
|
|
if (STATE.slideshow.slideInterval) {
|
|
|
|
|
STATE.slideshow.slideInterval.stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Pause active video if playing
|
|
|
|
|
const currentItemId = STATE.slideshow.itemIds[STATE.slideshow.currentSlideIndex];
|
|
|
|
|
if (currentItemId) {
|
|
|
|
|
// YouTube
|
|
|
|
|
if (STATE.slideshow.videoPlayers && STATE.slideshow.videoPlayers[currentItemId]) {
|
|
|
|
|
const player = STATE.slideshow.videoPlayers[currentItemId];
|
|
|
|
|
if (typeof player.pauseVideo === "function") {
|
|
|
|
|
try {
|
|
|
|
|
player.pauseVideo();
|
|
|
|
|
STATE.slideshow.isVideoPlaying = false;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.warn("Error pausing video on tab hide:", e);
|
|
|
|
|
}
|
|
|
|
|
} else if (player.tagName === 'VIDEO') { // HTML5 Video
|
|
|
|
|
player.pause();
|
|
|
|
|
STATE.slideshow.isVideoPlaying = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
SlideshowManager.stopAllPlayback();
|
|
|
|
|
} else {
|
|
|
|
|
console.log("Tab active - resuming slideshow");
|
|
|
|
|
if (!STATE.slideshow.isPaused) {
|
|
|
|
|
const currentItemId = STATE.slideshow.itemIds[STATE.slideshow.currentSlideIndex];
|
|
|
|
|
// Only resume if we're on the home page and not paused
|
|
|
|
|
const isOnHome = window.location.hash === "#/home.html" || window.location.hash === "#/home";
|
|
|
|
|
const isVideoPlayerOpen = document.querySelector('.videoPlayerContainer:not(.hide)') || document.querySelector('.youtubePlayerContainer:not(.hide)');
|
|
|
|
|
|
|
|
|
|
if (wasVideoPlayingBeforeHide && currentItemId && STATE.slideshow.videoPlayers && STATE.slideshow.videoPlayers[currentItemId]) {
|
|
|
|
|
const player = STATE.slideshow.videoPlayers[currentItemId];
|
|
|
|
|
if (isOnHome && !STATE.slideshow.isPaused && !isVideoPlayerOpen) {
|
|
|
|
|
SlideshowManager.resumeActivePlayback();
|
|
|
|
|
|
|
|
|
|
// YouTube
|
|
|
|
|
if (typeof player.playVideo === "function") {
|
|
|
|
|
try {
|
|
|
|
|
player.playVideo();
|
|
|
|
|
STATE.slideshow.isVideoPlaying = true;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.warn("Error resuming video on tab show:", e);
|
|
|
|
|
if (STATE.slideshow.slideInterval) {
|
|
|
|
|
STATE.slideshow.slideInterval.start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (player.tagName === 'VIDEO') { // HTML5 Video
|
|
|
|
|
try {
|
|
|
|
|
player.play().catch(e => console.warn("Error resuming HTML5 video:", e));
|
|
|
|
|
STATE.slideshow.isVideoPlaying = true;
|
|
|
|
|
} catch(e) { console.warn(e); }
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// No video was playing, just restart interval
|
|
|
|
|
const activeSlide = document.querySelector('.slide.active');
|
|
|
|
|
const hasVideo = activeSlide && activeSlide.querySelector('.video-backdrop');
|
|
|
|
|
|
|
|
|
|
if (CONFIG.waitForTrailerToEnd && hasVideo) {
|
|
|
|
|
// Don't restart interval if waiting for trailer
|
|
|
|
|
} else {
|
|
|
|
|
if (STATE.slideshow.slideInterval) {
|
|
|
|
|
STATE.slideshow.slideInterval.start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (STATE.slideshow.slideInterval && !CONFIG.waitForTrailerToEnd) {
|
|
|
|
|
STATE.slideshow.slideInterval.start();
|
|
|
|
|
}
|
|
|
|
|
wasVideoPlayingBeforeHide = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|