mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-07-15 17:02:58 +01:00
wip
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// hooks/useFileOpener.ts
|
||||
|
||||
import { usePlayback } from "@/providers/PlaybackProvider";
|
||||
import { usePlaySettings } from "@/providers/PlaySettingsProvider";
|
||||
import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import * as FileSystem from "expo-file-system";
|
||||
import { useRouter } from "expo-router";
|
||||
@@ -8,48 +8,44 @@ import { useCallback } from "react";
|
||||
|
||||
export const useFileOpener = () => {
|
||||
const router = useRouter();
|
||||
const { startDownloadedFilePlayback } = usePlayback();
|
||||
const { setPlaySettings, setPlayUrl, setOfflineSettings } = usePlaySettings();
|
||||
|
||||
const openFile = useCallback(
|
||||
async (item: BaseItemDto) => {
|
||||
const directory = FileSystem.documentDirectory;
|
||||
const openFile = useCallback(async (item: BaseItemDto) => {
|
||||
const directory = FileSystem.documentDirectory;
|
||||
|
||||
if (!directory) {
|
||||
throw new Error("Document directory is not available");
|
||||
if (!directory) {
|
||||
throw new Error("Document directory is not available");
|
||||
}
|
||||
|
||||
if (!item.Id) {
|
||||
throw new Error("Item ID is not available");
|
||||
}
|
||||
|
||||
try {
|
||||
const files = await FileSystem.readDirectoryAsync(directory);
|
||||
for (let f of files) {
|
||||
console.log(f);
|
||||
}
|
||||
const path = item.Id!;
|
||||
const matchingFile = files.find((file) => file.startsWith(path));
|
||||
|
||||
if (!matchingFile) {
|
||||
throw new Error(`No file found for item ${path}`);
|
||||
}
|
||||
|
||||
if (!item.Id) {
|
||||
throw new Error("Item ID is not available");
|
||||
}
|
||||
const url = `${directory}${matchingFile}`;
|
||||
|
||||
try {
|
||||
const files = await FileSystem.readDirectoryAsync(directory);
|
||||
for (let f of files) {
|
||||
console.log(f);
|
||||
}
|
||||
const path = item.Id!;
|
||||
const matchingFile = files.find((file) => file.startsWith(path));
|
||||
setOfflineSettings({
|
||||
item,
|
||||
});
|
||||
setPlayUrl(url);
|
||||
|
||||
if (!matchingFile) {
|
||||
throw new Error(`No file found for item ${path}`);
|
||||
}
|
||||
|
||||
const url = `${directory}${matchingFile}`;
|
||||
|
||||
console.log("Opening " + url);
|
||||
|
||||
startDownloadedFilePlayback({
|
||||
item,
|
||||
url,
|
||||
});
|
||||
router.push("/play");
|
||||
} catch (error) {
|
||||
console.error("Error opening file:", error);
|
||||
// Handle the error appropriately, e.g., show an error message to the user
|
||||
}
|
||||
},
|
||||
[startDownloadedFilePlayback]
|
||||
);
|
||||
router.push("/play-offline-video");
|
||||
} catch (error) {
|
||||
console.error("Error opening file:", error);
|
||||
// Handle the error appropriately, e.g., show an error message to the user
|
||||
}
|
||||
}, []);
|
||||
|
||||
return { openFile };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user