Compare commits

..

13 Commits

Author SHA1 Message Date
CodeDevMLH
d489c22f28 Update manifest.json for release v1.6.1.24 [skip ci] 2026-02-14 01:12:45 +00:00
CodeDevMLH
7816c87543 Bump version to 1.6.1.24
All checks were successful
Auto Release Plugin / build-and-release (push) Successful in 1m19s
2026-02-14 02:11:09 +01:00
CodeDevMLH
720567bafc Enhance video playback logic with improved state handling and retry mechanism for YouTube players 2026-02-14 02:10:55 +01:00
CodeDevMLH
2289a1f83e Update manifest.json for release v1.6.1.23 [skip ci] 2026-02-14 00:58:27 +00:00
CodeDevMLH
a269318f58 Bump version to 1.6.1.23
All checks were successful
Auto Release Plugin / build-and-release (push) Successful in 51s
2026-02-14 01:57:36 +01:00
CodeDevMLH
fdb409fd3b Merge branch 'main' of ssh://git.mahom03-spacecloud.de:44322/CodeDevMLH/jellyfin-plugin-media-bar-enhanced 2026-02-14 01:57:18 +01:00
CodeDevMLH
9bb4b9d355 Refactor video playback logic to improve handling of active slides and paused state 2026-02-14 01:57:14 +01:00
CodeDevMLH
1e18c22937 Update manifest.json for release v1.6.1.22 [skip ci] 2026-02-14 00:43:45 +00:00
CodeDevMLH
a83913d15c Bump version to 1.6.1.22
All checks were successful
Auto Release Plugin / build-and-release (push) Successful in 53s
2026-02-14 01:42:53 +01:00
CodeDevMLH
2f50931beb Fix YouTube player readiness checks and improve polling logic for video playback 2026-02-14 01:42:42 +01:00
CodeDevMLH
5b14bdba35 Update manifest.json for release v1.6.1.21 [skip ci] 2026-02-14 00:35:03 +00:00
CodeDevMLH
9ba3b1e49f Bump version to 1.6.1.21
All checks were successful
Auto Release Plugin / build-and-release (push) Successful in 53s
2026-02-14 01:34:12 +01:00
CodeDevMLH
bf7c7fb8e8 Enhance video backdrop handling to support YouTube iframe integration and improve video playback logic 2026-02-14 01:33:54 +01:00
3 changed files with 142 additions and 72 deletions

View File

@@ -12,7 +12,7 @@
<!-- <TreatWarningsAsErrors>false</TreatWarningsAsErrors> --> <!-- <TreatWarningsAsErrors>false</TreatWarningsAsErrors> -->
<Title>Jellyfin Media Bar Enhanced Plugin</Title> <Title>Jellyfin Media Bar Enhanced Plugin</Title>
<Authors>CodeDevMLH</Authors> <Authors>CodeDevMLH</Authors>
<Version>1.6.1.20</Version> <Version>1.6.1.24</Version>
<RepositoryUrl>https://github.com/CodeDevMLH/jellyfin-plugin-media-bar-enhanced</RepositoryUrl> <RepositoryUrl>https://github.com/CodeDevMLH/jellyfin-plugin-media-bar-enhanced</RepositoryUrl>
</PropertyGroup> </PropertyGroup>

View File

@@ -1719,6 +1719,13 @@ const SlideCreator = {
if (iframe) { if (iframe) {
iframe.setAttribute('tabindex', '-1'); iframe.setAttribute('tabindex', '-1');
iframe.setAttribute('inert', ''); iframe.setAttribute('inert', '');
// Preserve video-backdrop class on the iframe (YT API replaces the original div)
iframe.classList.add('backdrop', 'video-backdrop');
if (CONFIG.fullWidthVideo) {
iframe.classList.add('video-backdrop-full');
} else {
iframe.classList.add('video-backdrop-default');
}
} }
// Store start/end time and videoId for later use // Store start/end time and videoId for later use
@@ -1737,18 +1744,18 @@ const SlideCreator = {
event.target.setPlaybackQuality(quality); event.target.setPlaybackQuality(quality);
} }
// Only play if this is the active slide AND the slideshow is visible // Only play if this is the active slide and not paused
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');
// Check _pendingPlay flag (set by playCurrentVideo when player wasn't ready yet) const isActive = slide && slide.classList.contains('active');
const container = document.getElementById(`youtube-player-${itemId}`); const isHidden = document.hidden;
const hasPendingPlay = container && container._pendingPlay; const isPaused = STATE.slideshow.isPaused;
if (container) container._pendingPlay = false; const isPlayerOpen = isVideoPlayerOpen && !isVideoPlayerOpen.classList.contains('hide');
console.log(`[MBE-READY] onReady for ${itemId}: active=${isActive}, hidden=${isHidden}, paused=${isPaused}, playerOpen=${!!isPlayerOpen}`);
const isActiveAndVisible = slide && slide.classList.contains('active') && !document.hidden && (!isVideoPlayerOpen || isVideoPlayerOpen.classList.contains('hide')); if (isActive && !isHidden && !isPaused && !isPlayerOpen) {
console.log(`[MBE-READY] → Playing video for ${itemId}`);
if ((isActiveAndVisible || hasPendingPlay) && !STATE.slideshow.isPaused) {
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)
@@ -1781,6 +1788,8 @@ const SlideCreator = {
} }
}, },
'onStateChange': (event) => { 'onStateChange': (event) => {
const stateNames = {[-1]: 'UNSTARTED', 0: 'ENDED', 1: 'PLAYING', 2: 'PAUSED', 3: 'BUFFERING', 5: 'CUED'};
console.log(`[MBE-STATE] ${itemId}: ${stateNames[event.data] || event.data}`);
if (event.data === YT.PlayerState.ENDED) { if (event.data === YT.PlayerState.ENDED) {
SlideshowManager.nextSlide(); SlideshowManager.nextSlide();
} }
@@ -2333,28 +2342,26 @@ const SlideshowManager = {
// Manage Video Playback: Stop others, Play current // Manage Video Playback: Stop others, Play current
this.pauseOtherVideos(currentItemId); this.pauseOtherVideos(currentItemId);
const hasVideoBackdrop = !!currentSlide.querySelector('.video-backdrop');
// If paused and new slide has video, un-pause for video playback.
// If paused and new slide has only images, stay paused.
if (STATE.slideshow.isPaused && hasVideoBackdrop) {
STATE.slideshow.isPaused = false;
const pauseButton = document.querySelector('.pause-button');
if (pauseButton) {
pauseButton.innerHTML = '<i class="material-icons">pause</i>';
const pauseLabel = LocalizationUtils.getLocalizedString('ButtonPause', 'Pause');
pauseButton.setAttribute('aria-label', pauseLabel);
pauseButton.setAttribute('title', pauseLabel);
}
}
if (!STATE.slideshow.isPaused) { if (!STATE.slideshow.isPaused) {
this.playCurrentVideo(currentSlide, currentItemId); this.playCurrentVideo(currentSlide, currentItemId);
} else { } else {
// Still update mute button visibility based on video presence // Check if new slide has video — Option B: un-pause for video slides
const videoBackdrop = currentSlide.querySelector('.video-backdrop');
if (videoBackdrop) {
STATE.slideshow.isPaused = false;
const pauseButton = document.querySelector('.pause-button');
if (pauseButton) {
pauseButton.innerHTML = '<i class="material-icons">pause</i>';
const pauseLabel = LocalizationUtils.getLocalizedString('ButtonPause', 'Pause');
pauseButton.setAttribute('aria-label', pauseLabel);
pauseButton.setAttribute('title', pauseLabel);
}
this.playCurrentVideo(currentSlide, currentItemId);
}
// Update mute button visibility
const muteButton = document.querySelector('.mute-button'); const muteButton = document.querySelector('.mute-button');
if (muteButton) { if (muteButton) {
muteButton.style.display = hasVideoBackdrop ? 'block' : 'none'; muteButton.style.display = videoBackdrop ? 'block' : 'none';
} }
} }
@@ -2391,7 +2398,8 @@ const SlideshowManager = {
this.updateDots(); this.updateDots();
// Only restart interval if we are NOT waiting for a video to end // Only restart interval if we are NOT waiting for a video to end
const hasVideo = currentSlide.querySelector('.video-backdrop'); const hasVideo = currentSlide.querySelector('.video-backdrop') ||
(STATE.slideshow.videoPlayers && STATE.slideshow.videoPlayers[currentItemId]);
if (STATE.slideshow.slideInterval && !STATE.slideshow.isPaused) { if (STATE.slideshow.slideInterval && !STATE.slideshow.isPaused) {
if (CONFIG.waitForTrailerToEnd && hasVideo) { if (CONFIG.waitForTrailerToEnd && hasVideo) {
STATE.slideshow.slideInterval.stop(); STATE.slideshow.slideInterval.stop();
@@ -2706,23 +2714,33 @@ const SlideshowManager = {
}, },
/** /**
* Plays the video backdrop on the given slide and updates mute button visibility * Plays the video backdrop on the given slide and updates mute button visibility.
* Includes a retry mechanism for YouTube players that aren't ready yet.
* @param {Element} slide - The slide DOM element * @param {Element} slide - The slide DOM element
* @param {string} itemId - The item ID of the slide * @param {string} itemId - The item ID of the slide
* @returns {boolean} Whether a video was found and playback attempted
*/ */
playCurrentVideo(slide, itemId) { playCurrentVideo(slide, itemId) {
// Find video element — check class (covers both original div and iframe with class restored by onReady)
const videoBackdrop = slide.querySelector('.video-backdrop'); const videoBackdrop = slide.querySelector('.video-backdrop');
const ytPlayer = STATE.slideshow.videoPlayers && STATE.slideshow.videoPlayers[itemId];
const hasAnyVideo = !!(videoBackdrop || ytPlayer);
console.log(`[MBE-PLAY] playCurrentVideo for ${itemId}: videoBackdrop=${videoBackdrop?.tagName || 'null'}, ytPlayer=${!!ytPlayer}, ytReady=${ytPlayer && typeof ytPlayer.loadVideoById === 'function'}`);
// Update mute button visibility // Update mute button visibility
const muteButton = document.querySelector('.mute-button'); const muteButton = document.querySelector('.mute-button');
if (muteButton) { if (muteButton) {
muteButton.style.display = videoBackdrop ? 'block' : 'none'; muteButton.style.display = hasAnyVideo ? 'block' : 'none';
} }
if (!videoBackdrop) return false; if (!hasAnyVideo) {
console.log(`[MBE-PLAY] No video found for ${itemId}, skipping`);
return;
}
if (videoBackdrop.tagName === 'VIDEO') { // HTML5 <video> element
if (videoBackdrop && videoBackdrop.tagName === 'VIDEO') {
console.log(`[MBE-PLAY] Playing HTML5 video for ${itemId}`);
videoBackdrop.currentTime = 0; videoBackdrop.currentTime = 0;
videoBackdrop.muted = STATE.slideshow.isMuted; videoBackdrop.muted = STATE.slideshow.isMuted;
if (!STATE.slideshow.isMuted) videoBackdrop.volume = 0.4; if (!STATE.slideshow.isMuted) videoBackdrop.volume = 0.4;
@@ -2730,61 +2748,113 @@ const SlideshowManager = {
videoBackdrop.play().catch(() => { videoBackdrop.play().catch(() => {
setTimeout(() => { setTimeout(() => {
if (videoBackdrop.paused && slide.classList.contains('active')) { if (videoBackdrop.paused && slide.classList.contains('active')) {
console.warn(`Autoplay blocked for ${itemId}, attempting muted fallback`); console.warn(`[MBE-PLAY] Autoplay blocked for ${itemId}, muted fallback`);
videoBackdrop.muted = true; videoBackdrop.muted = true;
videoBackdrop.play().catch(err => console.error("Muted fallback failed", err)); videoBackdrop.play().catch(err => console.error('[MBE-PLAY] Muted fallback failed', err));
} }
}, 1000); }, 1000);
}); });
return true; return;
} }
// YouTube player // YouTube player — try to play now if ready
const player = STATE.slideshow.videoPlayers && STATE.slideshow.videoPlayers[itemId]; if (ytPlayer && typeof ytPlayer.loadVideoById === 'function' && ytPlayer._videoId) {
if (player && typeof player.loadVideoById === 'function' && player._videoId) { console.log(`[MBE-PLAY] YouTube player READY for ${itemId}, calling loadVideoById`);
player.loadVideoById({ ytPlayer.loadVideoById({
videoId: player._videoId, videoId: ytPlayer._videoId,
startSeconds: player._startTime || 0, startSeconds: ytPlayer._startTime || 0,
endSeconds: player._endTime endSeconds: ytPlayer._endTime
}); });
if (STATE.slideshow.isMuted) { if (STATE.slideshow.isMuted) {
player.mute(); ytPlayer.mute();
} else { } else {
player.unMute(); ytPlayer.unMute();
player.setVolume(40); ytPlayer.setVolume(40);
} }
// Pause slideshow timer for video if configured
if (CONFIG.waitForTrailerToEnd && STATE.slideshow.slideInterval) {
STATE.slideshow.slideInterval.stop();
}
// 1s check: if still not playing, force muted retry
setTimeout(() => { setTimeout(() => {
if (!slide.classList.contains('active')) return; if (!slide.classList.contains('active')) return;
try {
const state = ytPlayer.getPlayerState();
if (state !== YT.PlayerState.PLAYING && state !== YT.PlayerState.BUFFERING) {
console.warn(`[MBE-PLAY] loadVideoById didn't start for ${itemId} (state=${state}), muted retry`);
ytPlayer.mute();
ytPlayer.playVideo();
}
} catch (e) { console.warn('[MBE-PLAY] Error checking player state:', e); }
}, 1500);
return;
}
if (player.getPlayerState && // YouTube player NOT ready yet (onReady hasn't fired).
player.getPlayerState() !== YT.PlayerState.PLAYING && // onReady will handle it IF the slide is still active when it fires.
player.getPlayerState() !== YT.PlayerState.BUFFERING) { // But as safety net: retry every 500ms for up to 6 seconds.
console.log("YouTube loadVideoById didn't start playback, retrying muted..."); console.log(`[MBE-PLAY] YouTube player NOT READY for ${itemId}, starting retry loop (onReady will also attempt)`);
player.mute(); let retryCount = 0;
player.playVideo(); const maxRetries = 12; // 12 × 500ms = 6 seconds
const retryTimer = setInterval(() => {
retryCount++;
// Abort if slide changed or paused
if (!slide.classList.contains('active') || STATE.slideshow.isPaused) {
console.log(`[MBE-PLAY] Retry aborted for ${itemId} (slide inactive or paused)`);
clearInterval(retryTimer);
return;
}
const p = STATE.slideshow.videoPlayers && STATE.slideshow.videoPlayers[itemId];
// Check if player is now playing (onReady may have started it)
if (p && typeof p.getPlayerState === 'function') {
try {
const state = p.getPlayerState();
if (state === YT.PlayerState.PLAYING || state === YT.PlayerState.BUFFERING) {
console.log(`[MBE-PLAY] Player for ${itemId} is already playing (started by onReady), stopping retry`);
clearInterval(retryTimer);
return;
}
} catch (e) { /* player not fully ready yet */ }
}
// Check if player is now ready
if (p && typeof p.loadVideoById === 'function' && p._videoId) {
console.log(`[MBE-PLAY] Retry #${retryCount}: Player for ${itemId} now READY, calling loadVideoById`);
clearInterval(retryTimer);
p.loadVideoById({
videoId: p._videoId,
startSeconds: p._startTime || 0,
endSeconds: p._endTime
});
if (STATE.slideshow.isMuted) {
p.mute();
} else {
p.unMute();
p.setVolume(40);
} }
}, 1000);
return true;
} else if (player && typeof player.seekTo === 'function') {
// Fallback if loadVideoById is not available or videoId missing but player object exists
const startTime = player._startTime || 0;
player.seekTo(startTime);
player.playVideo();
return true;
}
// YouTube player not ready yet (still loading from preload) — mark for auto-play when onReady fires if (CONFIG.waitForTrailerToEnd && STATE.slideshow.slideInterval) {
if (videoBackdrop && videoBackdrop.id && videoBackdrop.id.startsWith('youtube-player-') && !player) { STATE.slideshow.slideInterval.stop();
console.log(`YouTube player for ${itemId} not ready yet, marking _pendingPlay`); }
videoBackdrop._pendingPlay = true; return;
return true; }
}
return false; if (retryCount >= maxRetries) {
console.warn(`[MBE-PLAY] Gave up retrying for ${itemId} after ${maxRetries * 500}ms`);
clearInterval(retryTimer);
}
}, 500);
}, },
/** /**
* Stops all video playback (YouTube and HTML5) * Stops all video playback (YouTube and HTML5)
* Used when navigating away from the home screen * Used when navigating away from the home screen

View File

@@ -9,12 +9,12 @@
"imageUrl": "https://git.mahom03-spacecloud.de/CodeDevMLH/jellyfin-plugin-media-bar-enhanced/raw/branch/main/logo.png", "imageUrl": "https://git.mahom03-spacecloud.de/CodeDevMLH/jellyfin-plugin-media-bar-enhanced/raw/branch/main/logo.png",
"versions": [ "versions": [
{ {
"version": "1.6.1.20", "version": "1.6.1.24",
"changelog": "- fix tv mode issue\n- refactor video playback management", "changelog": "- fix tv mode issue\n- refactor video playback management",
"targetAbi": "10.11.0.0", "targetAbi": "10.11.0.0",
"sourceUrl": "https://git.mahom03-spacecloud.de/CodeDevMLH/jellyfin-plugin-media-bar-enhanced/releases/download/v1.6.1.20/Jellyfin.Plugin.MediaBarEnhanced.zip", "sourceUrl": "https://git.mahom03-spacecloud.de/CodeDevMLH/jellyfin-plugin-media-bar-enhanced/releases/download/v1.6.1.24/Jellyfin.Plugin.MediaBarEnhanced.zip",
"checksum": "e3ed985f3e00f8124502faad46bd160d", "checksum": "466a2504753288ac48d3a9fd6b697f27",
"timestamp": "2026-02-14T00:10:57Z" "timestamp": "2026-02-14T01:12:44Z"
}, },
{ {
"version": "1.6.0.2", "version": "1.6.0.2",