This commit is contained in:
MLH
2024-12-28 01:48:25 +01:00
parent 548aafb019
commit cdceb555f0

View File

@@ -27,17 +27,17 @@ let forwardMovies = [];
let monitorOutroInterval = null; // Global interval variable to monitor the outro segment of the trailer let monitorOutroInterval = null; // Global interval variable to monitor the outro segment of the trailer
if (setMutedHover) { if (setMutedHover) {
const slidesContainer = document.getElementById('slides-container'); const hoverContainer = document.getElementById('slides-container');
slidesContainer.addEventListener('mouseenter', () => { hoverContainer.addEventListener('mouseenter', () => {
if (player) { if (player) {
player.unMute(); player.setVolume(unmutedVolume);
isMuted = false; isMuted = false;
} }
}); });
slidesContainer.addEventListener('mouseleave', () => { hoverContainer.addEventListener('mouseleave', () => {
if (player) { if (player) {
player.mute(); player.setVolume(0);
isMuted = true; isMuted = true;
} }
}); });
@@ -90,6 +90,13 @@ function monitorOutro(player, outroSegment) {
}, 500); // check every 500ms }, 500); // check every 500ms
} }
const clearMonitorOutroInterval = () => {
if (monitorOutroInterval) {
clearInterval(monitorOutroInterval);
monitorOutroInterval = null;
}
};
const createElem = (tag, className, textContent, src, alt) => { const createElem = (tag, className, textContent, src, alt) => {
const elem = document.createElement(tag); const elem = document.createElement(tag);
@@ -114,6 +121,7 @@ const cleanup = () => {
player = null; player = null;
clearTimeout(slideChangeTimeout); clearTimeout(slideChangeTimeout);
slideChangeTimeout = null; slideChangeTimeout = null;
clearMonitorOutroInterval();
const container = document.getElementById('slides-container'); const container = document.getElementById('slides-container');
if (container) container.innerHTML = ''; if (container) container.innerHTML = '';
}; };
@@ -291,11 +299,11 @@ const createSlideElement = (movie, hasVideo = false) => {
mute: isMuted ? 1 : 0, // CHeck if the video should start muted mute: isMuted ? 1 : 0, // CHeck if the video should start muted
controls: disableTrailerControls ? 0 : 1, // Hide the controls controls: disableTrailerControls ? 0 : 1, // Hide the controls
disablekb: 1, // Disable keyboard controls disablekb: 1, // Disable keyboard controls
fs: 1, // Enavle fullscreen
iv_load_policy: 3, // Disable annotations iv_load_policy: 3, // Disable annotations
cc_load_policy: 3, // Disable captions
}, },
events: { events: {
'onReady': event => { 'onReady': () => {
if (useSponsorBlock) { if (useSponsorBlock) {
fetchSponsorBlockData(videoId).then(({ intro, outro }) => { fetchSponsorBlockData(videoId).then(({ intro, outro }) => {
if (intro && skipIntro) { if (intro && skipIntro) {
@@ -320,6 +328,7 @@ const createSlideElement = (movie, hasVideo = false) => {
if (trailerMaxLength > 0) { if (trailerMaxLength > 0) {
clearTimeout(slideChangeTimeout); clearTimeout(slideChangeTimeout);
slideChangeTimeout = setTimeout(() => { slideChangeTimeout = setTimeout(() => {
clearMonitorOutroInterval();
if (player) { if (player) {
player.stopVideo(); player.stopVideo();
player.destroy(); player.destroy();
@@ -329,14 +338,16 @@ const createSlideElement = (movie, hasVideo = false) => {
}, trailerMaxLength); }, trailerMaxLength);
} }
if (isMuted) { if (isMuted) {
event.target.setVolume(0); // Mute the video if the setting is MuteOn player.setVolume(0); // Mute the video if the setting is MuteOn
} else { } else {
event.target.setVolume(unmutedVolume); // Set the volume, value between 0 and 100 player.setVolume(unmutedVolume); // Set the volume, value between 0 and 100
} }
event.target.playVideo();
player.playVideo();
console.log(`Playing trailer for '${movie.Name}'`);
}, },
'onStateChange': event => { 'onStateChange': () => {
if (event.data === YT.PlayerState.PLAYING) { if (player.getPlayerState() === YT.PlayerState.PLAYING) {
// Only show when YT video is successfully playing // Only show when YT video is successfully playing
const backdrop = document.querySelector('.backdrop'); const backdrop = document.querySelector('.backdrop');
if (backdrop) { if (backdrop) {
@@ -361,14 +372,21 @@ const createSlideElement = (movie, hasVideo = false) => {
if (logo) logo.style.left = 'calc(50% - 17vw)'; if (logo) logo.style.left = 'calc(50% - 17vw)';
videoContainer.style.width = '34.4vw'; videoContainer.style.width = '34.4vw';
} else if (event.data === YT.PlayerState.ENDED) { /*} else if (player.getPlayerState() === YT.PlayerState.CUED) {
setTimeout(fetchRandomMovie, 100); console.log('Video cued - attempting restart');
player.playVideo();
} else if (player.getPlayerState() === -1) {
console.log('Video unstarted - attempting restart');
player.playVideo();*/
} else if (player.getPlayerState() === YT.PlayerState.ENDED) {
clearMonitorOutroInterval();
setTimeout(fetchRandomMovie, 20);
} }
}, },
'onError': () => { 'onError': () => {
console.error(`YouTube prevented playback of '${movie.Name}'`); console.error(`YouTube prevented playback of '${movie.Name}'`);
if (player) { if (player) {
clearInterval(monitorOutroInterval); clearMonitorOutroInterval();
player.destroy(); player.destroy();
player = null; player = null;
} }