Implement play signal management for slideshow video playback

This commit is contained in:
CodeDevMLH
2026-03-24 00:43:17 +01:00
parent 664eecf779
commit eecb81d59a

View File

@@ -112,6 +112,7 @@ const STATE = {
customTrailerUrls: {},
ytPromise: null,
autoplayTimeouts: [],
playSignals: {},
},
};
@@ -398,6 +399,7 @@ const resetSlideshowState = () => {
STATE.slideshow.customTrailerUrls = {};
STATE.slideshow.totalItems = 0;
STATE.slideshow.isLoading = false;
STATE.slideshow.playSignals = {};
};
/**
@@ -1883,7 +1885,7 @@ const SlideCreator = {
const slide = document.querySelector(`.slide[data-item-id="${itemId}"]`);
const isVideoPlayerOpen = document.querySelector('.videoPlayerContainer') || document.querySelector('.youtubePlayerContainer');
if (slide && slide.classList.contains('active') && slide.dataset.playVideoSignal === "true" && !document.hidden && (!isVideoPlayerOpen || isVideoPlayerOpen.classList.contains('hide'))) {
if (slide && slide.classList.contains('active') && STATE.slideshow.playSignals[itemId] === true && !document.hidden && (!isVideoPlayerOpen || isVideoPlayerOpen.classList.contains('hide'))) {
event.target.playVideo();
// Check if it actually started playing after a short delay (handling autoplay blocks)
@@ -2481,7 +2483,7 @@ const SlideshowManager = {
void currentSlide.offsetWidth;
currentSlide.classList.add("active");
currentSlide.dataset.playVideoSignal = "false";
STATE.slideshow.playSignals[currentItemId] = false;
// Manage Video Playback: Stop others, Play current
// 1. Stop all other YouTube players and local video elements, release connections
@@ -2583,7 +2585,7 @@ const SlideshowManager = {
const playVideoLogic = () => {
if (!currentSlide.classList.contains('active')) return;
currentSlide.dataset.playVideoSignal = "true";
STATE.slideshow.playSignals[currentItemId] = true;
if (videoBackdrop.tagName === 'VIDEO') {
videoBackdrop.play().catch(e => {