mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-30 16:17:41 +01:00
Fix issue with next episode vol. 4
This commit is contained in:
parent
80bfa3b27d
commit
a945fcc4c5
2 changed files with 34 additions and 23 deletions
|
@ -395,8 +395,8 @@
|
||||||
},
|
},
|
||||||
"nextEpisode": {
|
"nextEpisode": {
|
||||||
"replay": "Replay",
|
"replay": "Replay",
|
||||||
"next": "Next episode",
|
"nextIn": "Next episode in {{seconds}}",
|
||||||
"nextIn": "Next episode in {{seconds}}"
|
"next": "Next Episode"
|
||||||
},
|
},
|
||||||
"playbackError": {
|
"playbackError": {
|
||||||
"badge": "Playback error",
|
"badge": "Playback error",
|
||||||
|
|
|
@ -95,30 +95,41 @@ export function NextEpisodeButton(props: {
|
||||||
}, [setDirectMeta, meta, props, setShouldStartFromBeginning]);
|
}, [setDirectMeta, meta, props, setShouldStartFromBeginning]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Check if we should start the countdown to automatically go to the next episode.
|
// Function to calculate the initial countdown value based on current time and duration.
|
||||||
const startCountdown = shouldStartCountdown(time, duration);
|
const calculateCountdown = () => {
|
||||||
|
const secondsFromEnd = duration - time;
|
||||||
|
if (secondsFromEnd <= 30) {
|
||||||
|
return Math.max(secondsFromEnd, 0); // Ensure countdown doesn't go below 0.
|
||||||
|
}
|
||||||
|
return 15; // Default countdown start value if within the last 30 seconds.
|
||||||
|
};
|
||||||
|
|
||||||
if (startCountdown && countdown === 15) {
|
// Update countdown based on current playback time.
|
||||||
const intervalId = window.setInterval(() => {
|
const updateCountdown = () => {
|
||||||
setCountdown((currentCountdown) => {
|
if (status === "playing") {
|
||||||
if (currentCountdown <= 1) {
|
const newCountdown = calculateCountdown();
|
||||||
loadNextEpisode(); // Load next episode when countdown reaches 0.
|
setCountdown(newCountdown);
|
||||||
window.clearInterval(intervalId); // Clear the interval.
|
}
|
||||||
return 0;
|
};
|
||||||
}
|
|
||||||
return currentCountdown - 1;
|
// Call updateCountdown initially and whenever relevant dependencies change.
|
||||||
});
|
updateCountdown();
|
||||||
|
|
||||||
|
// Set up an interval to update the countdown every second if the video is playing.
|
||||||
|
let intervalId: number | null = null;
|
||||||
|
if (status === "playing") {
|
||||||
|
intervalId = window.setInterval(() => {
|
||||||
|
updateCountdown();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
// Cleanup function to clear the interval when the component unmounts or the dependencies change.
|
// Cleanup function to clear the interval when the component unmounts or dependencies change.
|
||||||
return () => window.clearInterval(intervalId);
|
return () => {
|
||||||
}
|
if (intervalId) {
|
||||||
if (!startCountdown) {
|
clearInterval(intervalId);
|
||||||
// Reset countdown when conditions are not met.
|
}
|
||||||
setCountdown(15);
|
};
|
||||||
}
|
}, [time, duration, status]); // Depend on time, duration, and status to re-evaluate when they change.
|
||||||
// Removed countdown from the dependencies to prevent resetting it unnecessarily.
|
|
||||||
}, [time, duration, countdown, loadNextEpisode]);
|
|
||||||
|
|
||||||
if (!meta?.episode || !nextEp) return null;
|
if (!meta?.episode || !nextEp) return null;
|
||||||
if (metaType !== "show") return null;
|
if (metaType !== "show") return null;
|
||||||
|
|
Loading…
Reference in a new issue