|
|
|
|
@@ -1258,9 +1258,20 @@ const ApiUtils = {
|
|
|
|
|
*/
|
|
|
|
|
async fetchSponsorBlockData(videoId) {
|
|
|
|
|
if (!CONFIG.useSponsorBlock) return { intro: null, outro: null };
|
|
|
|
|
|
|
|
|
|
// Return cached result if available
|
|
|
|
|
if (!this._sponsorBlockCache) this._sponsorBlockCache = {};
|
|
|
|
|
if (this._sponsorBlockCache[videoId]) {
|
|
|
|
|
return this._sponsorBlockCache[videoId];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`https://sponsor.ajay.app/api/skipSegments?videoID=${videoId}&categories=["intro","outro"]`);
|
|
|
|
|
if (!response.ok) return { intro: null, outro: null };
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const result = { intro: null, outro: null };
|
|
|
|
|
this._sponsorBlockCache[videoId] = result;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const segments = await response.json();
|
|
|
|
|
let intro = null;
|
|
|
|
|
@@ -1274,7 +1285,9 @@ const ApiUtils = {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return { intro, outro };
|
|
|
|
|
const result = { intro, outro };
|
|
|
|
|
this._sponsorBlockCache[videoId] = result;
|
|
|
|
|
return result;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.warn('Error fetching SponsorBlock data:', error);
|
|
|
|
|
return { intro: null, outro: null };
|
|
|
|
|
@@ -1435,19 +1448,16 @@ 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'))) {
|
|
|
|
|
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();
|
|
|
|
|
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();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1462,27 +1472,20 @@ const VisibilityObserver = {
|
|
|
|
|
activeTab &&
|
|
|
|
|
activeTab.getAttribute("data-index") === "0";
|
|
|
|
|
|
|
|
|
|
const newState = isVisible ? 'visible' : 'hidden';
|
|
|
|
|
|
|
|
|
|
// 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";
|
|
|
|
|
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();
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
@@ -1491,11 +1494,6 @@ const VisibilityObserver = {
|
|
|
|
|
*/
|
|
|
|
|
init() {
|
|
|
|
|
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());
|
|
|
|
|
@@ -1622,6 +1620,11 @@ const SlideCreator = {
|
|
|
|
|
else if (item.RemoteTrailers && item.RemoteTrailers.length > 0) {
|
|
|
|
|
trailerUrl = item.RemoteTrailers[0].Url;
|
|
|
|
|
}
|
|
|
|
|
// 1d. Final Fallback to Local Trailer (even if not preferred)
|
|
|
|
|
else if (item.LocalTrailerCount > 0 && item.localTrailerUrl) {
|
|
|
|
|
trailerUrl = item.localTrailerUrl;
|
|
|
|
|
console.log(`Using local trailer fallback for ${itemId}: ${trailerUrl}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
|
|
|
|
|
|
|
|
@@ -1714,20 +1717,6 @@ 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', '');
|
|
|
|
|
// Preserve video-backdrop class on the iframe (YT API replaces the original div)
|
|
|
|
|
iframe.classList.add('backdrop', 'video-backdrop');
|
|
|
|
|
if (CONFIG.fullWidthVideo) {
|
|
|
|
|
iframe.classList.add('video-backdrop-full');
|
|
|
|
|
} else {
|
|
|
|
|
iframe.classList.add('video-backdrop-default');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Store start/end time and videoId for later use
|
|
|
|
|
event.target._startTime = playerVars.start || 0;
|
|
|
|
|
event.target._endTime = playerVars.end || undefined;
|
|
|
|
|
@@ -1744,18 +1733,11 @@ const SlideCreator = {
|
|
|
|
|
event.target.setPlaybackQuality(quality);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Only play if this is the active slide AND the slideshow is visible
|
|
|
|
|
// Only play if this is the active slide
|
|
|
|
|
const slide = document.querySelector(`.slide[data-item-id="${itemId}"]`);
|
|
|
|
|
const isVideoPlayerOpen = document.querySelector('.videoPlayerContainer') || document.querySelector('.youtubePlayerContainer');
|
|
|
|
|
|
|
|
|
|
// Check _pendingPlay flag (set by playCurrentVideo when player wasn't ready yet)
|
|
|
|
|
const container = document.getElementById(`youtube-player-${itemId}`);
|
|
|
|
|
const hasPendingPlay = container && container._pendingPlay;
|
|
|
|
|
if (container) container._pendingPlay = false;
|
|
|
|
|
|
|
|
|
|
const isActiveAndVisible = slide && slide.classList.contains('active') && !document.hidden && (!isVideoPlayerOpen || isVideoPlayerOpen.classList.contains('hide'));
|
|
|
|
|
|
|
|
|
|
if ((isActiveAndVisible || hasPendingPlay) && !STATE.slideshow.isPaused) {
|
|
|
|
|
if (slide && slide.classList.contains('active') && !document.hidden && (!isVideoPlayerOpen || isVideoPlayerOpen.classList.contains('hide'))) {
|
|
|
|
|
event.target.playVideo();
|
|
|
|
|
|
|
|
|
|
// Check if it actually started playing after a short delay (handling autoplay blocks)
|
|
|
|
|
@@ -1789,7 +1771,14 @@ const SlideCreator = {
|
|
|
|
|
},
|
|
|
|
|
'onStateChange': (event) => {
|
|
|
|
|
if (event.data === YT.PlayerState.ENDED) {
|
|
|
|
|
SlideshowManager.nextSlide();
|
|
|
|
|
const slide = document.querySelector(`.slide[data-item-id="${itemId}"]`);
|
|
|
|
|
if (slide && slide.classList.contains('active')) {
|
|
|
|
|
if (CONFIG.waitForTrailerToEnd) {
|
|
|
|
|
SlideshowManager.nextSlide();
|
|
|
|
|
} else {
|
|
|
|
|
event.target.playVideo(); // Loop if trailer is shorter than slide duration
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
'onError': (event) => {
|
|
|
|
|
@@ -1818,39 +1807,36 @@ const SlideCreator = {
|
|
|
|
|
style: "object-fit: cover; object-position: center center; width: 100%; height: 100%; position: absolute; top: 0; left: 0; pointer-events: none;"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (STATE.slideshow.isMuted) {
|
|
|
|
|
videoAttributes.muted = "";
|
|
|
|
|
}
|
|
|
|
|
videoAttributes.muted = "";
|
|
|
|
|
|
|
|
|
|
backdrop = SlideUtils.createElement("video", videoAttributes);
|
|
|
|
|
|
|
|
|
|
if (!STATE.slideshow.isMuted) {
|
|
|
|
|
backdrop.volume = 0.4;
|
|
|
|
|
}
|
|
|
|
|
backdrop.volume = 0.4;
|
|
|
|
|
|
|
|
|
|
STATE.slideshow.videoPlayers[itemId] = backdrop;
|
|
|
|
|
|
|
|
|
|
backdrop.addEventListener('play', (event) => {
|
|
|
|
|
const slide = document.querySelector(`.slide[data-item-id="${itemId}"]`);
|
|
|
|
|
|
|
|
|
|
if (!slide || !slide.classList.contains('active')) {
|
|
|
|
|
console.log(`Local video ${itemId} started playing but is not active, pausing.`);
|
|
|
|
|
event.target.pause();
|
|
|
|
|
event.target.currentTime = 0;
|
|
|
|
|
return;
|
|
|
|
|
console.log(`Local video ${itemId} started playing but slide is not active, pausing.`);
|
|
|
|
|
event.target.pause();
|
|
|
|
|
event.target.currentTime = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CONFIG.waitForTrailerToEnd && STATE.slideshow.slideInterval) {
|
|
|
|
|
STATE.slideshow.slideInterval.stop();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
backdrop.addEventListener('ended', () => {
|
|
|
|
|
SlideshowManager.nextSlide();
|
|
|
|
|
const slide = document.querySelector(`.slide[data-item-id="${itemId}"]`);
|
|
|
|
|
if (slide && slide.classList.contains('active')) {
|
|
|
|
|
SlideshowManager.nextSlide();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
backdrop.addEventListener('error', () => {
|
|
|
|
|
if (CONFIG.waitForTrailerToEnd) {
|
|
|
|
|
const slide = document.querySelector(`.slide[data-item-id="${itemId}"]`);
|
|
|
|
|
if (CONFIG.waitForTrailerToEnd && slide && slide.classList.contains('active')) {
|
|
|
|
|
SlideshowManager.nextSlide();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
@@ -2281,16 +2267,6 @@ 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));
|
|
|
|
|
@@ -2315,56 +2291,127 @@ const SlideshowManager = {
|
|
|
|
|
|
|
|
|
|
if (previousVisibleSlide) {
|
|
|
|
|
previousVisibleSlide.classList.remove("active");
|
|
|
|
|
// previousVisibleSlide.setAttribute("inert", "");
|
|
|
|
|
// previousVisibleSlide.setAttribute("tabindex", "-1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentSlide.classList.add("active");
|
|
|
|
|
// // Update Play/Pause Button State if it was paused
|
|
|
|
|
// if (STATE.slideshow.isPaused) {
|
|
|
|
|
// STATE.slideshow.isPaused = false;
|
|
|
|
|
// const pauseButton = document.querySelector('.pause-button');
|
|
|
|
|
// if (pauseButton) {
|
|
|
|
|
// pauseButton.innerHTML = '<i class="material-icons">pause</i>';
|
|
|
|
|
// const pauseLabel = LocalizationUtils.getLocalizedString('ButtonPause', 'Pause');
|
|
|
|
|
// pauseButton.setAttribute("aria-label", pauseLabel);
|
|
|
|
|
// pauseButton.setAttribute("title", pauseLabel);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// Restore focus for TV mode navigation continuity
|
|
|
|
|
requestAnimationFrame(() => {
|
|
|
|
|
if (focusSelector) {
|
|
|
|
|
const target = currentSlide.querySelector(focusSelector);
|
|
|
|
|
if (target) {
|
|
|
|
|
target.focus();
|
|
|
|
|
return;
|
|
|
|
|
// Manage Video Playback: Stop others, Play current
|
|
|
|
|
|
|
|
|
|
// 1. Stop all other YouTube players and local video elements
|
|
|
|
|
if (STATE.slideshow.videoPlayers) {
|
|
|
|
|
Object.keys(STATE.slideshow.videoPlayers).forEach(id => {
|
|
|
|
|
if (id !== currentItemId) {
|
|
|
|
|
const p = STATE.slideshow.videoPlayers[id];
|
|
|
|
|
if (!p) return;
|
|
|
|
|
// YouTube player
|
|
|
|
|
if (typeof p.pauseVideo === 'function') {
|
|
|
|
|
p.pauseVideo();
|
|
|
|
|
}
|
|
|
|
|
// HTML5 <video> element (local trailers)
|
|
|
|
|
if (p instanceof HTMLVideoElement) {
|
|
|
|
|
p.pause();
|
|
|
|
|
p.muted = true;
|
|
|
|
|
p.currentTime = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 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 });
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Manage Video Playback: Stop others, Play current
|
|
|
|
|
this.pauseOtherVideos(currentItemId);
|
|
|
|
|
// 3. Play and Reset current video
|
|
|
|
|
const videoBackdrop = currentSlide.querySelector('.video-backdrop');
|
|
|
|
|
|
|
|
|
|
// Check for video backdrop (also check by YouTube player ID since YT replaces div with iframe)
|
|
|
|
|
const hasVideoBackdrop = !!(currentSlide.querySelector('.video-backdrop') ||
|
|
|
|
|
currentSlide.querySelector(`#youtube-player-${currentItemId}`) ||
|
|
|
|
|
(STATE.slideshow.videoPlayers && STATE.slideshow.videoPlayers[currentItemId]));
|
|
|
|
|
|
|
|
|
|
// If paused and new slide has video, un-pause for video playback.
|
|
|
|
|
// If paused and new slide has only images, stay paused.
|
|
|
|
|
if (STATE.slideshow.isPaused && hasVideoBackdrop) {
|
|
|
|
|
STATE.slideshow.isPaused = false;
|
|
|
|
|
const pauseButton = document.querySelector('.pause-button');
|
|
|
|
|
if (pauseButton) {
|
|
|
|
|
pauseButton.innerHTML = '<i class="material-icons">pause</i>';
|
|
|
|
|
const pauseLabel = LocalizationUtils.getLocalizedString('ButtonPause', 'Pause');
|
|
|
|
|
pauseButton.setAttribute('aria-label', pauseLabel);
|
|
|
|
|
pauseButton.setAttribute('title', pauseLabel);
|
|
|
|
|
}
|
|
|
|
|
// Auto-unpause when a video slide becomes active
|
|
|
|
|
if (videoBackdrop && STATE.slideshow.isPaused) {
|
|
|
|
|
STATE.slideshow.isPaused = false;
|
|
|
|
|
const pauseButton = document.querySelector('.pause-button');
|
|
|
|
|
if (pauseButton) {
|
|
|
|
|
pauseButton.innerHTML = '<i class="material-icons">pause</i>';
|
|
|
|
|
const pauseLabel = LocalizationUtils.getLocalizedString('ButtonPause', 'Pause');
|
|
|
|
|
pauseButton.setAttribute("aria-label", pauseLabel);
|
|
|
|
|
pauseButton.setAttribute("title", pauseLabel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!STATE.slideshow.isPaused) {
|
|
|
|
|
this.playCurrentVideo(currentSlide, currentItemId);
|
|
|
|
|
} else {
|
|
|
|
|
// Still update mute button visibility based on video presence
|
|
|
|
|
const muteButton = document.querySelector('.mute-button');
|
|
|
|
|
if (muteButton) {
|
|
|
|
|
muteButton.style.display = hasVideoBackdrop ? 'block' : 'none';
|
|
|
|
|
// 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 && currentSlide.classList.contains('active')) {
|
|
|
|
|
console.warn(`Autoplay blocked for ${currentItemId}, 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 (!currentSlide.classList.contains('active')) return;
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -2402,7 +2449,6 @@ const SlideshowManager = {
|
|
|
|
|
|
|
|
|
|
// Only restart interval if we are NOT waiting for a video to end
|
|
|
|
|
const hasVideo = currentSlide.querySelector('.video-backdrop') ||
|
|
|
|
|
currentSlide.querySelector(`#youtube-player-${currentItemId}`) ||
|
|
|
|
|
(STATE.slideshow.videoPlayers && STATE.slideshow.videoPlayers[currentItemId]);
|
|
|
|
|
if (STATE.slideshow.slideInterval && !STATE.slideshow.isPaused) {
|
|
|
|
|
if (CONFIG.waitForTrailerToEnd && hasVideo) {
|
|
|
|
|
@@ -2462,14 +2508,18 @@ const SlideshowManager = {
|
|
|
|
|
async preloadAdjacentSlides(currentIndex) {
|
|
|
|
|
const totalItems = STATE.slideshow.totalItems;
|
|
|
|
|
const preloadCount = Math.min(Math.max(CONFIG.preloadCount || 1, 1), 5);
|
|
|
|
|
const preloadedIds = new Set();
|
|
|
|
|
|
|
|
|
|
// Preload next slides
|
|
|
|
|
for (let i = 1; i <= preloadCount; i++) {
|
|
|
|
|
const nextIndex = (currentIndex + i) % totalItems;
|
|
|
|
|
if (nextIndex === currentIndex) break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const itemId = STATE.slideshow.itemIds[nextIndex];
|
|
|
|
|
SlideCreator.createSlideForItemId(itemId);
|
|
|
|
|
if (!preloadedIds.has(itemId)) {
|
|
|
|
|
preloadedIds.add(itemId);
|
|
|
|
|
SlideCreator.createSlideForItemId(itemId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Preload previous slides
|
|
|
|
|
@@ -2478,7 +2528,10 @@ const SlideshowManager = {
|
|
|
|
|
if (prevIndex === currentIndex) break;
|
|
|
|
|
|
|
|
|
|
const prevItemId = STATE.slideshow.itemIds[prevIndex];
|
|
|
|
|
SlideCreator.createSlideForItemId(prevItemId);
|
|
|
|
|
if (!preloadedIds.has(prevItemId)) {
|
|
|
|
|
preloadedIds.add(prevItemId);
|
|
|
|
|
SlideCreator.createSlideForItemId(prevItemId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
@@ -2514,13 +2567,11 @@ const SlideshowManager = {
|
|
|
|
|
if (index === -1) return;
|
|
|
|
|
|
|
|
|
|
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]) {
|
|
|
|
|
@@ -2545,13 +2596,11 @@ const SlideshowManager = {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 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') {
|
|
|
|
|
@@ -2665,9 +2714,7 @@ const SlideshowManager = {
|
|
|
|
|
// Only restart interval if we are NOT waiting for a video to end
|
|
|
|
|
const currentItemId = STATE.slideshow.itemIds[STATE.slideshow.currentSlideIndex];
|
|
|
|
|
const currentSlide = document.querySelector(`.slide[data-item-id="${currentItemId}"]`);
|
|
|
|
|
const hasVideo = currentSlide && (currentSlide.querySelector('.video-backdrop') ||
|
|
|
|
|
currentSlide.querySelector(`#youtube-player-${currentItemId}`) ||
|
|
|
|
|
(STATE.slideshow.videoPlayers && STATE.slideshow.videoPlayers[currentItemId]));
|
|
|
|
|
const hasVideo = currentSlide && currentSlide.querySelector('.video-backdrop');
|
|
|
|
|
|
|
|
|
|
if (!CONFIG.waitForTrailerToEnd || !hasVideo) {
|
|
|
|
|
STATE.slideshow.slideInterval.start();
|
|
|
|
|
@@ -2680,132 +2727,6 @@ 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) {
|
|
|
|
|
// Try finding by class first, then fall back to YouTube player container by ID
|
|
|
|
|
let videoBackdrop = slide.querySelector('.video-backdrop');
|
|
|
|
|
if (!videoBackdrop) {
|
|
|
|
|
// YouTube API replaces the div with an iframe, which may not have the class yet
|
|
|
|
|
videoBackdrop = slide.querySelector(`#youtube-player-${itemId}`);
|
|
|
|
|
}
|
|
|
|
|
// Also check if a player exists in the registry even if no DOM element found
|
|
|
|
|
const hasRegisteredPlayer = !!(STATE.slideshow.videoPlayers && STATE.slideshow.videoPlayers[itemId]);
|
|
|
|
|
|
|
|
|
|
// Update mute button visibility
|
|
|
|
|
const muteButton = document.querySelector('.mute-button');
|
|
|
|
|
if (muteButton) {
|
|
|
|
|
muteButton.style.display = (videoBackdrop || hasRegisteredPlayer) ? 'block' : 'none';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!videoBackdrop && !hasRegisteredPlayer) 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 && slide.classList.contains('active')) {
|
|
|
|
|
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 && 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 (!slide.classList.contains('active')) return;
|
|
|
|
|
|
|
|
|
|
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') {
|
|
|
|
|
// Fallback if loadVideoById is not available or videoId missing but player object exists
|
|
|
|
|
const startTime = player._startTime || 0;
|
|
|
|
|
player.seekTo(startTime);
|
|
|
|
|
player.playVideo();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// YouTube player not ready yet (still loading from preload) — mark for auto-play when onReady fires
|
|
|
|
|
if (videoBackdrop && videoBackdrop.id && videoBackdrop.id.startsWith('youtube-player-') && !player) {
|
|
|
|
|
console.log(`YouTube player for ${itemId} not ready yet, marking _pendingPlay`);
|
|
|
|
|
videoBackdrop._pendingPlay = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Stops all video playback (YouTube and HTML5)
|
|
|
|
|
* Used when navigating away from the home screen
|
|
|
|
|
@@ -2954,7 +2875,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)
|
|
|
|
|
let canControlSlideshow = isTvMode ? hasDirectFocus : (hasDirectFocus || isBodyFocused);
|
|
|
|
|
const canControlSlideshow = isTvMode ? hasDirectFocus : (hasDirectFocus || isBodyFocused);
|
|
|
|
|
|
|
|
|
|
// Check for Input Fields (always ignore typing)
|
|
|
|
|
const isInputElement = activeElement && (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA' || activeElement.isContentEditable);
|
|
|
|
|
@@ -3598,69 +3519,75 @@ const MediaBarEnhancedSettingsManager = {
|
|
|
|
|
* Initialize page visibility handling to pause when tab is inactive
|
|
|
|
|
*/
|
|
|
|
|
const initPageVisibilityHandler = () => {
|
|
|
|
|
document.addEventListener("visibilitychange", () => {
|
|
|
|
|
const isVideoPlayerOpen = document.querySelector('.videoPlayerContainer:not(.hide)') ||
|
|
|
|
|
document.querySelector('.youtubePlayerContainer:not(.hide)');
|
|
|
|
|
let wasVideoPlayingBeforeHide = false;
|
|
|
|
|
|
|
|
|
|
document.addEventListener("visibilitychange", () => {
|
|
|
|
|
if (document.hidden) {
|
|
|
|
|
// Stop slide timer
|
|
|
|
|
console.log("Tab inactive - pausing slideshow and videos");
|
|
|
|
|
wasVideoPlayingBeforeHide = STATE.slideshow.isVideoPlaying;
|
|
|
|
|
|
|
|
|
|
if (STATE.slideshow.slideInterval) {
|
|
|
|
|
STATE.slideshow.slideInterval.stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isVideoPlayerOpen) {
|
|
|
|
|
// Jellyfin video is playing --> full stop to free all resources
|
|
|
|
|
console.log("Tab inactive and Jellyfin player active - stopping all playback");
|
|
|
|
|
SlideshowManager.stopAllPlayback();
|
|
|
|
|
} else {
|
|
|
|
|
// Simple tab switch: stop all others, pause only the current
|
|
|
|
|
console.log("Tab inactive. Pausing current video, stopping others");
|
|
|
|
|
const currentItemId = STATE.slideshow.itemIds?.[STATE.slideshow.currentSlideIndex];
|
|
|
|
|
|
|
|
|
|
// Stop all players except the current one
|
|
|
|
|
if (STATE.slideshow.videoPlayers) {
|
|
|
|
|
Object.keys(STATE.slideshow.videoPlayers).forEach(id => {
|
|
|
|
|
if (id === currentItemId) return;
|
|
|
|
|
const p = STATE.slideshow.videoPlayers[id];
|
|
|
|
|
if (p) {
|
|
|
|
|
try {
|
|
|
|
|
if (typeof p.stopVideo === 'function') {
|
|
|
|
|
p.stopVideo();
|
|
|
|
|
if (typeof p.clearVideo === 'function') p.clearVideo();
|
|
|
|
|
} else if (p.tagName === 'VIDEO') {
|
|
|
|
|
p.pause();
|
|
|
|
|
p.muted = true;
|
|
|
|
|
p.currentTime = 0;
|
|
|
|
|
}
|
|
|
|
|
} catch (e) { console.warn("Error stopping background player", id, e); }
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Pause only the current video
|
|
|
|
|
if (currentItemId) {
|
|
|
|
|
const player = STATE.slideshow.videoPlayers?.[currentItemId];
|
|
|
|
|
if (player) {
|
|
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
|
if (typeof player.pauseVideo === 'function') {
|
|
|
|
|
player.pauseVideo();
|
|
|
|
|
} else if (player.tagName === 'VIDEO') {
|
|
|
|
|
player.pause();
|
|
|
|
|
}
|
|
|
|
|
} catch (e) { console.warn("Error pausing video on tab hide:", e); }
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
console.log("Tab active. Resuming slideshow");
|
|
|
|
|
const isOnHome = window.location.hash === "#/home.html" || window.location.hash === "#/home";
|
|
|
|
|
|
|
|
|
|
if (isOnHome && !STATE.slideshow.isPaused && !isVideoPlayerOpen) {
|
|
|
|
|
SlideshowManager.resumeActivePlayback();
|
|
|
|
|
|
|
|
|
|
if (STATE.slideshow.slideInterval && !CONFIG.waitForTrailerToEnd) {
|
|
|
|
|
STATE.slideshow.slideInterval.start();
|
|
|
|
|
console.log("Tab active - resuming slideshow");
|
|
|
|
|
if (!STATE.slideshow.isPaused) {
|
|
|
|
|
const currentItemId = STATE.slideshow.itemIds[STATE.slideshow.currentSlideIndex];
|
|
|
|
|
|
|
|
|
|
if (wasVideoPlayingBeforeHide && currentItemId && STATE.slideshow.videoPlayers && STATE.slideshow.videoPlayers[currentItemId]) {
|
|
|
|
|
const player = STATE.slideshow.videoPlayers[currentItemId];
|
|
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
wasVideoPlayingBeforeHide = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|