Enhance visibility change handling to manage video playback more effectively when tab visibility changes
This commit is contained in:
@@ -3517,17 +3517,61 @@ const MediaBarEnhancedSettingsManager = {
|
|||||||
*/
|
*/
|
||||||
const initPageVisibilityHandler = () => {
|
const initPageVisibilityHandler = () => {
|
||||||
document.addEventListener("visibilitychange", () => {
|
document.addEventListener("visibilitychange", () => {
|
||||||
|
const isVideoPlayerOpen = document.querySelector('.videoPlayerContainer:not(.hide)') ||
|
||||||
|
document.querySelector('.youtubePlayerContainer:not(.hide)');
|
||||||
|
|
||||||
if (document.hidden) {
|
if (document.hidden) {
|
||||||
console.log("Tab inactive - stopping all slideshow playback");
|
// Stop slide timer
|
||||||
if (STATE.slideshow.slideInterval) {
|
if (STATE.slideshow.slideInterval) {
|
||||||
STATE.slideshow.slideInterval.stop();
|
STATE.slideshow.slideInterval.stop();
|
||||||
}
|
}
|
||||||
SlideshowManager.stopAllPlayback();
|
|
||||||
|
if (isVideoPlayerOpen) {
|
||||||
|
// Jellyfin video is playing --> full stop to free all resources
|
||||||
|
console.log("Tab inactive and Jellyfin player active - stopping all playback");
|
||||||
|
SlideshowManager.stopAllPlayback();
|
||||||
|
} else {
|
||||||
|
// Simple tab switch: stop all others, pause only the current
|
||||||
|
console.log("Tab inactive. Pausing current video, stopping others");
|
||||||
|
const currentItemId = STATE.slideshow.itemIds?.[STATE.slideshow.currentSlideIndex];
|
||||||
|
|
||||||
|
// Stop all players except the current one
|
||||||
|
if (STATE.slideshow.videoPlayers) {
|
||||||
|
Object.keys(STATE.slideshow.videoPlayers).forEach(id => {
|
||||||
|
if (id === currentItemId) return;
|
||||||
|
const p = STATE.slideshow.videoPlayers[id];
|
||||||
|
if (p) {
|
||||||
|
try {
|
||||||
|
if (typeof p.stopVideo === 'function') {
|
||||||
|
p.stopVideo();
|
||||||
|
if (typeof p.clearVideo === 'function') p.clearVideo();
|
||||||
|
} else if (p.tagName === 'VIDEO') {
|
||||||
|
p.pause();
|
||||||
|
p.muted = true;
|
||||||
|
p.currentTime = 0;
|
||||||
|
}
|
||||||
|
} catch (e) { console.warn("Error stopping background player", id, e); }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pause only the current video
|
||||||
|
if (currentItemId) {
|
||||||
|
const player = STATE.slideshow.videoPlayers?.[currentItemId];
|
||||||
|
if (player) {
|
||||||
|
try {
|
||||||
|
if (typeof player.pauseVideo === 'function') {
|
||||||
|
player.pauseVideo();
|
||||||
|
} else if (player.tagName === 'VIDEO') {
|
||||||
|
player.pause();
|
||||||
|
}
|
||||||
|
} catch (e) { console.warn("Error pausing video on tab hide:", e); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("Tab active - resuming slideshow");
|
console.log("Tab active. Resuming slideshow");
|
||||||
// Only resume if we're on the home page and not paused
|
|
||||||
const isOnHome = window.location.hash === "#/home.html" || window.location.hash === "#/home";
|
const isOnHome = window.location.hash === "#/home.html" || window.location.hash === "#/home";
|
||||||
const isVideoPlayerOpen = document.querySelector('.videoPlayerContainer:not(.hide)') || document.querySelector('.youtubePlayerContainer:not(.hide)');
|
|
||||||
|
|
||||||
if (isOnHome && !STATE.slideshow.isPaused && !isVideoPlayerOpen) {
|
if (isOnHome && !STATE.slideshow.isPaused && !isVideoPlayerOpen) {
|
||||||
SlideshowManager.resumeActivePlayback();
|
SlideshowManager.resumeActivePlayback();
|
||||||
|
|||||||
Reference in New Issue
Block a user