mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-01-15 23:59:08 +00:00
wip
This commit is contained in:
@@ -13,13 +13,40 @@ export const useFileOpener = () => {
|
||||
const openFile = useCallback(
|
||||
async (item: BaseItemDto) => {
|
||||
const directory = FileSystem.documentDirectory;
|
||||
const url = `${directory}/${item.Id}.mp4`;
|
||||
|
||||
startDownloadedFilePlayback({
|
||||
item,
|
||||
url,
|
||||
});
|
||||
router.push("/play");
|
||||
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}`);
|
||||
}
|
||||
|
||||
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]
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user