forked from Ninjalama/streamyfin_mirror
Co-authored-by: lostb1t <coding-mosses0z@icloud.com> Co-authored-by: Fredrik Burmester <fredrik.burmester@gmail.com> Co-authored-by: Gauvain <68083474+Gauvino@users.noreply.github.com> Co-authored-by: Gauvino <uruknarb20@gmail.com> Co-authored-by: storm1er <le.storm1er@gmail.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Chris <182387676+whoopsi-daisy@users.noreply.github.com> Co-authored-by: arch-fan <55891793+arch-fan@users.noreply.github.com> Co-authored-by: Alex Kim <alexkim@Alexs-MacBook-Pro.local>
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
|
import { useRouter } from "expo-router";
|
|
import { useCallback } from "react";
|
|
import { usePlaySettings } from "@/providers/PlaySettingsProvider";
|
|
import { writeToLog } from "@/utils/log";
|
|
|
|
export const useDownloadedFileOpener = () => {
|
|
const router = useRouter();
|
|
const { setPlayUrl, setOfflineSettings } = usePlaySettings();
|
|
|
|
const openFile = useCallback(
|
|
async (item: BaseItemDto) => {
|
|
if (!item.Id) {
|
|
writeToLog("ERROR", "Attempted to open a file without an ID.");
|
|
console.error("Attempted to open a file without an ID.");
|
|
return;
|
|
}
|
|
const queryParams = new URLSearchParams({
|
|
itemId: item.Id,
|
|
offline: "true",
|
|
playbackPosition:
|
|
item.UserData?.PlaybackPositionTicks?.toString() ?? "0",
|
|
});
|
|
try {
|
|
router.push(`/player/direct-player?${queryParams.toString()}`);
|
|
} catch (error) {
|
|
writeToLog("ERROR", "Error opening file", error);
|
|
console.error("Error opening file:", error);
|
|
}
|
|
},
|
|
[setOfflineSettings, setPlayUrl, router],
|
|
);
|
|
|
|
return { openFile };
|
|
};
|