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