Add stopAllPlayback method to pause all video playback when navigating away from home screen

This commit is contained in:
CodeDevMLH
2026-01-08 15:52:46 +01:00
parent fe661925e0
commit 0f6938a91d

View File

@@ -1264,6 +1264,7 @@ const VisibilityObserver = {
if (STATE.slideshow.slideInterval) { if (STATE.slideshow.slideInterval) {
STATE.slideshow.slideInterval.stop(); STATE.slideshow.slideInterval.stop();
} }
SlideshowManager.stopAllPlayback();
} }
}, },
@@ -2317,6 +2318,37 @@ const SlideshowManager = {
} }
}, },
/**
* Stops all video playback (YouTube and HTML5)
* Used when navigating away from the home screen
*/
stopAllPlayback() {
// 1. Pause all YouTube players
if (STATE.slideshow.videoPlayers) {
Object.values(STATE.slideshow.videoPlayers).forEach(player => {
try {
if (player && typeof player.pauseVideo === 'function') {
player.pauseVideo();
}
} catch (e) {
console.warn("Error pausing YouTube player:", e);
}
});
}
// 2. Pause all HTML5 videos
const container = document.getElementById("slides-container");
if (container) {
container.querySelectorAll('video').forEach(video => {
try {
video.pause();
} catch (e) {
console.warn("Error pausing HTML5 video:", e);
}
});
}
},
/** /**
* Initializes touch events for swiping * Initializes touch events for swiping
*/ */