diff --git a/Jellyfin.Plugin.MediaBarEnhanced/Web/mediaBarEnhanced.js b/Jellyfin.Plugin.MediaBarEnhanced/Web/mediaBarEnhanced.js index 07bf2e8..b7cd049 100644 --- a/Jellyfin.Plugin.MediaBarEnhanced/Web/mediaBarEnhanced.js +++ b/Jellyfin.Plugin.MediaBarEnhanced/Web/mediaBarEnhanced.js @@ -1800,7 +1800,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(); } @@ -2476,18 +2487,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); } },