This commit is contained in:
Fredrik Burmester
2024-09-30 16:34:54 +02:00
parent 0263ad6109
commit 7ce2c90376
9 changed files with 331 additions and 285 deletions

View File

@@ -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]
);