|
|
|
|
@@ -163,6 +163,14 @@ const isUserLoggedIn = () => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Detects if the current device is a low-power device (Smart TVs, etc.)
|
|
|
|
|
* @returns {boolean} True if running on a low-power device
|
|
|
|
|
*/
|
|
|
|
|
const isLowPowerDevice = () => {
|
|
|
|
|
return /webOS|LG Browser|SMART-TV|SmartTV|Tizen|Viera|NetCast|Roku|VIDAA/i.test(navigator.userAgent);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initializes Jellyfin data from ApiClient
|
|
|
|
|
* @param {Function} callback - Function to call once data is initialized
|
|
|
|
|
@@ -1403,7 +1411,7 @@ const ApiUtils = {
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
id: trailer.Id,
|
|
|
|
|
url: `${STATE.jellyfinData.serverAddress}/Videos/${trailer.Id}/stream.mp4?mediaSourceId=${mediaSourceId}&api_key=${STATE.jellyfinData.accessToken}`
|
|
|
|
|
url: `${STATE.jellyfinData.serverAddress}/Videos/${trailer.Id}/stream.mp4?mediaSourceId=${mediaSourceId}&api_key=${STATE.jellyfinData.accessToken}&static=true`
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
@@ -1442,7 +1450,7 @@ const ApiUtils = {
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
id: video.Id,
|
|
|
|
|
url: `${STATE.jellyfinData.serverAddress}/Videos/${video.Id}/stream.mp4?api_key=${STATE.jellyfinData.accessToken}`
|
|
|
|
|
url: `${STATE.jellyfinData.serverAddress}/Videos/${video.Id}/stream.mp4?api_key=${STATE.jellyfinData.accessToken}&static=true`
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -1668,7 +1676,7 @@ const SlideCreator = {
|
|
|
|
|
|
|
|
|
|
trailerUrl = {
|
|
|
|
|
id: videoId,
|
|
|
|
|
url: `${STATE.jellyfinData.serverAddress}/Videos/${videoId}/stream.mp4?api_key=${STATE.jellyfinData.accessToken}`
|
|
|
|
|
url: `${STATE.jellyfinData.serverAddress}/Videos/${videoId}/stream.mp4?api_key=${STATE.jellyfinData.accessToken}&static=true`
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
// Assume it's a standard URL (YouTube, etc.)
|
|
|
|
|
@@ -1696,7 +1704,7 @@ const SlideCreator = {
|
|
|
|
|
console.log(`Using local trailer fallback for ${itemId}: ${trailerUrl}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
|
|
|
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
|
|
|
|
|
|
|
|
// Client Setting Overrides
|
|
|
|
|
const enableVideo = MediaBarEnhancedSettingsManager.getSetting('videoBackdrops', CONFIG.enableVideoBackdrop);
|
|
|
|
|
@@ -1726,7 +1734,12 @@ const SlideCreator = {
|
|
|
|
|
console.warn("Invalid trailer URL:", trailerUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isYoutube && videoId) {
|
|
|
|
|
const isLowPower = isLowPowerDevice();
|
|
|
|
|
const itemIndex = STATE.slideshow.itemIds ? STATE.slideshow.itemIds.indexOf(itemId) : -1;
|
|
|
|
|
const isActiveSlide = itemIndex !== -1 && itemIndex === STATE.slideshow.currentSlideIndex;
|
|
|
|
|
const shouldCreateVideo = !isLowPower || isActiveSlide;
|
|
|
|
|
|
|
|
|
|
if (isYoutube && videoId && shouldCreateVideo) {
|
|
|
|
|
isVideo = true;
|
|
|
|
|
// Create container for YouTube API
|
|
|
|
|
const videoClass = CONFIG.fullWidthVideo ? "video-backdrop-full" : "video-backdrop-default";
|
|
|
|
|
@@ -1749,8 +1762,8 @@ const SlideCreator = {
|
|
|
|
|
// Fetch SponsorBlock data
|
|
|
|
|
ApiUtils.fetchSponsorBlockData(videoId).then(segments => {
|
|
|
|
|
const playerVars = {
|
|
|
|
|
autoplay: 1,
|
|
|
|
|
mute: 1, // need to be muted for Safari, because apple makes life difficult...
|
|
|
|
|
autoplay: 0,
|
|
|
|
|
mute: STATE.slideshow.isMuted ? 1 : 0,
|
|
|
|
|
controls: 0,
|
|
|
|
|
disablekb: 1,
|
|
|
|
|
fs: 0,
|
|
|
|
|
@@ -1808,8 +1821,9 @@ const SlideCreator = {
|
|
|
|
|
// Store reference to wrapper for fading
|
|
|
|
|
event.target._wrapperDiv = videoBackdrop;
|
|
|
|
|
|
|
|
|
|
// Unmute now if user wants sound.
|
|
|
|
|
if (!STATE.slideshow.isMuted) {
|
|
|
|
|
if (STATE.slideshow.isMuted) {
|
|
|
|
|
event.target.mute();
|
|
|
|
|
} else {
|
|
|
|
|
event.target.unMute();
|
|
|
|
|
event.target.setVolume(40);
|
|
|
|
|
}
|
|
|
|
|
@@ -1818,34 +1832,28 @@ const SlideCreator = {
|
|
|
|
|
event.target.setPlaybackQuality(quality);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Stop playback if slide was navigated away from
|
|
|
|
|
// 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');
|
|
|
|
|
|
|
|
|
|
if (!slide || !slide.classList.contains('active') || document.hidden || (isVideoPlayerOpen && !isVideoPlayerOpen.classList.contains('hide'))) {
|
|
|
|
|
event.target.stopVideo();
|
|
|
|
|
} else {
|
|
|
|
|
// Pause slideshow timer when video starts if configured
|
|
|
|
|
if (CONFIG.waitForTrailerToEnd && STATE.slideshow.slideInterval) {
|
|
|
|
|
STATE.slideshow.slideInterval.stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Safety check after 1s: handle navigation-away during the window,
|
|
|
|
|
// and fallback to muted play if autoplay failed for any reason.
|
|
|
|
|
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)
|
|
|
|
|
const timeoutId = setTimeout(() => {
|
|
|
|
|
// Re-check conditions before processing fallback
|
|
|
|
|
const isVideoPlayerOpenNow = document.querySelector('.videoPlayerContainer') || document.querySelector('.youtubePlayerContainer');
|
|
|
|
|
if (document.hidden || (isVideoPlayerOpenNow && !isVideoPlayerOpenNow.classList.contains('hide')) || !slide.classList.contains('active')) {
|
|
|
|
|
console.log(`Navigation detected during autoplay check for ${itemId}, stopping video.`);
|
|
|
|
|
try {
|
|
|
|
|
event.target.stopVideo();
|
|
|
|
|
} catch (e) { console.warn("Error stopping video:", e); }
|
|
|
|
|
return;
|
|
|
|
|
console.log(`Navigation detected during autoplay check for ${itemId}, stopping video.`);
|
|
|
|
|
try {
|
|
|
|
|
event.target.stopVideo();
|
|
|
|
|
} catch (e) { console.warn("Error stopping video in timeout:", e); }
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If somehow not playing/buffering yet, force muted fallback
|
|
|
|
|
const state = event.target.getPlayerState();
|
|
|
|
|
if (state !== YT.PlayerState.PLAYING && state !== YT.PlayerState.BUFFERING) {
|
|
|
|
|
console.warn(`Autoplay stalled for ${itemId}, attempting muted fallback`);
|
|
|
|
|
if (event.target.getPlayerState() !== YT.PlayerState.PLAYING &&
|
|
|
|
|
event.target.getPlayerState() !== YT.PlayerState.BUFFERING) {
|
|
|
|
|
console.warn(`Autoplay blocked for ${itemId}, attempting muted fallback`);
|
|
|
|
|
event.target.mute();
|
|
|
|
|
event.target.playVideo();
|
|
|
|
|
}
|
|
|
|
|
@@ -1853,6 +1861,11 @@ const SlideCreator = {
|
|
|
|
|
|
|
|
|
|
if (!STATE.slideshow.autoplayTimeouts) STATE.slideshow.autoplayTimeouts = [];
|
|
|
|
|
STATE.slideshow.autoplayTimeouts.push(timeoutId);
|
|
|
|
|
|
|
|
|
|
// Pause slideshow timer when video starts if configured
|
|
|
|
|
if (CONFIG.waitForTrailerToEnd && STATE.slideshow.slideInterval) {
|
|
|
|
|
STATE.slideshow.slideInterval.stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
'onStateChange': (event) => {
|
|
|
|
|
@@ -1883,7 +1896,7 @@ const SlideCreator = {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 2. Check for local video trailers in MediaSources if yt is not available
|
|
|
|
|
} else if (!isYoutube) {
|
|
|
|
|
} else if (!isYoutube && shouldCreateVideo) {
|
|
|
|
|
isVideo = true;
|
|
|
|
|
|
|
|
|
|
const videoSrc = (typeof trailerUrl === 'object' ? trailerUrl.url : trailerUrl);
|
|
|
|
|
@@ -1896,7 +1909,6 @@ const SlideCreator = {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
videoAttributes.muted = "";
|
|
|
|
|
videoAttributes.playsinline = ""; // again Safari needs extra treatment...
|
|
|
|
|
|
|
|
|
|
videoBackdrop = SlideUtils.createElement("video", videoAttributes);
|
|
|
|
|
videoBackdrop.volume = 0.4;
|
|
|
|
|
@@ -2467,58 +2479,42 @@ const SlideshowManager = {
|
|
|
|
|
if (videoBackdrop.tagName === 'VIDEO') {
|
|
|
|
|
// Restore src from data-src if it was deactivated to release connections
|
|
|
|
|
const lazySrc = videoBackdrop.getAttribute('data-src');
|
|
|
|
|
const isFreshLoad = lazySrc && !videoBackdrop.src;
|
|
|
|
|
if (lazySrc && !videoBackdrop.src) {
|
|
|
|
|
videoBackdrop.src = lazySrc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
videoBackdrop.currentTime = 0;
|
|
|
|
|
|
|
|
|
|
videoBackdrop.muted = STATE.slideshow.isMuted;
|
|
|
|
|
if (!STATE.slideshow.isMuted) {
|
|
|
|
|
videoBackdrop.volume = 0.4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const doPlay = () => {
|
|
|
|
|
if (!currentSlide.classList.contains('active')) return;
|
|
|
|
|
videoBackdrop.play().catch(e => {
|
|
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (isFreshLoad) {
|
|
|
|
|
// Safari: set src, then wait for loadedmetadata before seeking/playing
|
|
|
|
|
videoBackdrop.src = lazySrc;
|
|
|
|
|
videoBackdrop.load();
|
|
|
|
|
videoBackdrop.addEventListener('loadedmetadata', () => {
|
|
|
|
|
videoBackdrop.currentTime = 0;
|
|
|
|
|
doPlay();
|
|
|
|
|
}, { once: true });
|
|
|
|
|
} else {
|
|
|
|
|
// src already set (e.g. paused slide resuming)
|
|
|
|
|
videoBackdrop.currentTime = 0;
|
|
|
|
|
doPlay();
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
// load always starts muted first, then unmute if needed
|
|
|
|
|
player.loadVideoById({
|
|
|
|
|
videoId: player._videoId,
|
|
|
|
|
startSeconds: player._startTime || 0,
|
|
|
|
|
endSeconds: player._endTime
|
|
|
|
|
});
|
|
|
|
|
player.mute();
|
|
|
|
|
if (!STATE.slideshow.isMuted) {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
// Only unmute if still on the same slide
|
|
|
|
|
if (currentSlide.classList.contains('active')) {
|
|
|
|
|
player.unMute();
|
|
|
|
|
player.setVolume(40);
|
|
|
|
|
}
|
|
|
|
|
}, 600);
|
|
|
|
|
|
|
|
|
|
if (STATE.slideshow.isMuted) {
|
|
|
|
|
player.mute();
|
|
|
|
|
} else {
|
|
|
|
|
player.unMute();
|
|
|
|
|
player.setVolume(40);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if playback successfully started, otherwise fallback to muted
|
|
|
|
|
@@ -2592,7 +2588,7 @@ const SlideshowManager = {
|
|
|
|
|
STATE.slideshow.isTransitioning = false;
|
|
|
|
|
|
|
|
|
|
if (previousVisibleSlide) {
|
|
|
|
|
const enableAnimations = MediaBarEnhancedSettingsManager.getSetting('slideAnimations', CONFIG.slideAnimationEnabled);
|
|
|
|
|
const enableAnimations = MediaBarEnhancedSettingsManager.getSetting('slideAnimations', CONFIG.slideAnimationEnabled) && !isLowPowerDevice();
|
|
|
|
|
if (enableAnimations) {
|
|
|
|
|
const prevBackdrop = previousVisibleSlide.querySelector(".backdrop");
|
|
|
|
|
const prevLogo = previousVisibleSlide.querySelector(".logo");
|
|
|
|
|
@@ -2633,7 +2629,9 @@ const SlideshowManager = {
|
|
|
|
|
*/
|
|
|
|
|
async preloadAdjacentSlides(currentIndex) {
|
|
|
|
|
const totalItems = STATE.slideshow.totalItems;
|
|
|
|
|
const preloadCount = Math.min(Math.max(CONFIG.preloadCount || 1, 1), 5);
|
|
|
|
|
let preloadCount = Math.min(Math.max(CONFIG.preloadCount || 1, 1), 5);
|
|
|
|
|
if (isLowPowerDevice()) preloadCount = 1; // Strict limit for TVs
|
|
|
|
|
|
|
|
|
|
const preloadedIds = new Set();
|
|
|
|
|
|
|
|
|
|
// Preload next slides
|
|
|
|
|
|