mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-07-20 02:54:17 +01:00
Fixed intro skipper for VLC
This commit is contained in:
@@ -12,6 +12,7 @@ import { getDefaultPlaySettings } from "@/utils/jellyfin/getDefaultPlaySettings"
|
|||||||
import { writeToLog } from "@/utils/log";
|
import { writeToLog } from "@/utils/log";
|
||||||
import {
|
import {
|
||||||
formatTimeString,
|
formatTimeString,
|
||||||
|
msToSeconds,
|
||||||
msToTicks,
|
msToTicks,
|
||||||
secondsToMs,
|
secondsToMs,
|
||||||
ticksToMs,
|
ticksToMs,
|
||||||
@@ -130,14 +131,16 @@ export const Controls: React.FC<Props> = ({
|
|||||||
offline ? undefined : item.Id,
|
offline ? undefined : item.Id,
|
||||||
currentTime,
|
currentTime,
|
||||||
seek,
|
seek,
|
||||||
play
|
play,
|
||||||
|
isVlc
|
||||||
);
|
);
|
||||||
|
|
||||||
const { showSkipCreditButton, skipCredit } = useCreditSkipper(
|
const { showSkipCreditButton, skipCredit } = useCreditSkipper(
|
||||||
offline ? undefined : item.Id,
|
offline ? undefined : item.Id,
|
||||||
currentTime,
|
currentTime,
|
||||||
seek,
|
seek,
|
||||||
play
|
play,
|
||||||
|
isVlc
|
||||||
);
|
);
|
||||||
|
|
||||||
const goToPreviousItem = useCallback(() => {
|
const goToPreviousItem = useCallback(() => {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useAtom } from "jotai";
|
|||||||
import { apiAtom } from "@/providers/JellyfinProvider";
|
import { apiAtom } from "@/providers/JellyfinProvider";
|
||||||
import { getAuthHeaders } from "@/utils/jellyfin/jellyfin";
|
import { getAuthHeaders } from "@/utils/jellyfin/jellyfin";
|
||||||
import { writeToLog } from "@/utils/log";
|
import { writeToLog } from "@/utils/log";
|
||||||
|
import { msToSeconds, secondsToMs } from "@/utils/time";
|
||||||
|
|
||||||
interface CreditTimestamps {
|
interface CreditTimestamps {
|
||||||
Introduction: {
|
Introduction: {
|
||||||
@@ -22,11 +23,24 @@ export const useCreditSkipper = (
|
|||||||
itemId: string | undefined,
|
itemId: string | undefined,
|
||||||
currentTime: number,
|
currentTime: number,
|
||||||
seek: (time: number) => void,
|
seek: (time: number) => void,
|
||||||
play: () => void
|
play: () => void,
|
||||||
|
isVlc: boolean = false
|
||||||
) => {
|
) => {
|
||||||
const [api] = useAtom(apiAtom);
|
const [api] = useAtom(apiAtom);
|
||||||
const [showSkipCreditButton, setShowSkipCreditButton] = useState(false);
|
const [showSkipCreditButton, setShowSkipCreditButton] = useState(false);
|
||||||
|
|
||||||
|
if (isVlc) {
|
||||||
|
currentTime = msToSeconds(currentTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
const wrappedSeek = (seconds: number) => {
|
||||||
|
if (isVlc) {
|
||||||
|
seek(secondsToMs(seconds));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
seek(seconds);
|
||||||
|
};
|
||||||
|
|
||||||
const { data: creditTimestamps } = useQuery<CreditTimestamps | null>({
|
const { data: creditTimestamps } = useQuery<CreditTimestamps | null>({
|
||||||
queryKey: ["creditTimestamps", itemId],
|
queryKey: ["creditTimestamps", itemId],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
@@ -63,7 +77,7 @@ export const useCreditSkipper = (
|
|||||||
const skipCredit = useCallback(() => {
|
const skipCredit = useCallback(() => {
|
||||||
if (!creditTimestamps) return;
|
if (!creditTimestamps) return;
|
||||||
try {
|
try {
|
||||||
seek(creditTimestamps.Credits.End);
|
wrappedSeek(creditTimestamps.Credits.End);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
play();
|
play();
|
||||||
}, 200);
|
}, 200);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useAtom } from "jotai";
|
|||||||
import { apiAtom } from "@/providers/JellyfinProvider";
|
import { apiAtom } from "@/providers/JellyfinProvider";
|
||||||
import { getAuthHeaders } from "@/utils/jellyfin/jellyfin";
|
import { getAuthHeaders } from "@/utils/jellyfin/jellyfin";
|
||||||
import { writeToLog } from "@/utils/log";
|
import { writeToLog } from "@/utils/log";
|
||||||
|
import { msToSeconds, secondsToMs } from "@/utils/time";
|
||||||
|
|
||||||
interface IntroTimestamps {
|
interface IntroTimestamps {
|
||||||
EpisodeId: string;
|
EpisodeId: string;
|
||||||
@@ -14,14 +15,31 @@ interface IntroTimestamps {
|
|||||||
Valid: boolean;
|
Valid: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom hook to handle skipping intros in a media player.
|
||||||
|
*
|
||||||
|
* @param {number} currentTime - The current playback time in seconds.
|
||||||
|
*/
|
||||||
export const useIntroSkipper = (
|
export const useIntroSkipper = (
|
||||||
itemId: string | undefined,
|
itemId: string | undefined,
|
||||||
currentTime: number,
|
currentTime: number,
|
||||||
seek: (ticks: number) => void,
|
seek: (ticks: number) => void,
|
||||||
play: () => void
|
play: () => void,
|
||||||
|
isVlc: boolean = false
|
||||||
) => {
|
) => {
|
||||||
const [api] = useAtom(apiAtom);
|
const [api] = useAtom(apiAtom);
|
||||||
const [showSkipButton, setShowSkipButton] = useState(false);
|
const [showSkipButton, setShowSkipButton] = useState(false);
|
||||||
|
if (isVlc) {
|
||||||
|
currentTime = msToSeconds(currentTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
const wrappedSeek = (seconds: number) => {
|
||||||
|
if (isVlc) {
|
||||||
|
seek(secondsToMs(seconds));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
seek(seconds);
|
||||||
|
};
|
||||||
|
|
||||||
const { data: introTimestamps } = useQuery<IntroTimestamps | null>({
|
const { data: introTimestamps } = useQuery<IntroTimestamps | null>({
|
||||||
queryKey: ["introTimestamps", itemId],
|
queryKey: ["introTimestamps", itemId],
|
||||||
@@ -60,7 +78,7 @@ export const useIntroSkipper = (
|
|||||||
console.log("skipIntro");
|
console.log("skipIntro");
|
||||||
if (!introTimestamps) return;
|
if (!introTimestamps) return;
|
||||||
try {
|
try {
|
||||||
seek(introTimestamps.IntroEnd);
|
wrappedSeek(introTimestamps.IntroEnd);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
play();
|
play();
|
||||||
}, 200);
|
}, 200);
|
||||||
|
|||||||
Reference in New Issue
Block a user