mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 16:43:25 +00:00
chore: add repro button for expo issue lol
This commit is contained in:
@@ -1,29 +1,57 @@
|
||||
import type { Asset } from "expo-media-library";
|
||||
import React from "react";
|
||||
import { Platform } from "react-native";
|
||||
import { ScrollView } from "react-native-gesture-handler";
|
||||
import { useRouter } from "expo-router";
|
||||
import { MaterialCommunityIcons } from "@expo/vector-icons";
|
||||
import { useTheme } from "tamagui";
|
||||
|
||||
import { DownloadItem } from "~/components/DownloadItem";
|
||||
import ScreenLayout from "~/components/layout/ScreenLayout";
|
||||
import { MWButton } from "~/components/ui/Button";
|
||||
import { useDownloadManager } from "~/hooks/DownloadManagerContext";
|
||||
import { usePlayerStore } from "~/stores/player/store";
|
||||
|
||||
const DownloadsScreen: React.FC = () => {
|
||||
const { downloads, removeDownload } = useDownloadManager();
|
||||
const { startDownload, downloads, removeDownload } = useDownloadManager();
|
||||
const resetVideo = usePlayerStore((state) => state.resetVideo);
|
||||
const setAsset = usePlayerStore((state) => state.setAsset);
|
||||
const router = useRouter();
|
||||
const theme = useTheme();
|
||||
|
||||
const handlePress = (asset?: Asset) => {
|
||||
if (!asset) return;
|
||||
resetVideo();
|
||||
setAsset(asset);
|
||||
router.push({
|
||||
pathname: "/videoPlayer",
|
||||
params: { data: JSON.stringify(asset) },
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<ScreenLayout title="Downloads">
|
||||
<MWButton
|
||||
type="secondary"
|
||||
backgroundColor="$sheetItemBackground"
|
||||
icon={
|
||||
<MaterialCommunityIcons
|
||||
name={Platform.select({ ios: "apple", android: "android" })}
|
||||
size={24}
|
||||
color={theme.buttonSecondaryText.val}
|
||||
/>
|
||||
}
|
||||
onPress={async () => {
|
||||
const asset = await startDownload(
|
||||
"https://samplelib.com/lib/preview/mp4/sample-5s.mp4",
|
||||
"mp4",
|
||||
).catch(console.error);
|
||||
if (asset) {
|
||||
handlePress(asset);
|
||||
}
|
||||
}}
|
||||
>
|
||||
test local playback (expo-av)
|
||||
</MWButton>
|
||||
<ScrollView>
|
||||
{downloads.map((item) => (
|
||||
<DownloadItem
|
||||
|
@@ -23,7 +23,7 @@ export interface DownloadItem {
|
||||
|
||||
interface DownloadManagerContextType {
|
||||
downloads: DownloadItem[];
|
||||
startDownload: (url: string, type: "mp4" | "hls") => Promise<void>;
|
||||
startDownload: (url: string, type: "mp4" | "hls") => Promise<Asset | void>;
|
||||
removeDownload: (id: string) => void;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({
|
||||
url: string,
|
||||
type: "mp4" | "hls",
|
||||
headers?: Record<string, string>,
|
||||
) => {
|
||||
): Promise<Asset | void> => {
|
||||
toastController.show("Download started", {
|
||||
burntOptions: { preset: "none" },
|
||||
native: true,
|
||||
@@ -87,7 +87,8 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({
|
||||
setDownloads((currentDownloads) => [newDownload, ...currentDownloads]);
|
||||
|
||||
if (type === "mp4") {
|
||||
await downloadMP4(url, newDownload.id, headers ?? {});
|
||||
const asset = await downloadMP4(url, newDownload.id, headers ?? {});
|
||||
return asset;
|
||||
} else if (type === "hls") {
|
||||
// HLS stuff later
|
||||
}
|
||||
@@ -151,7 +152,11 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({
|
||||
const result = await downloadResumable.downloadAsync();
|
||||
if (result) {
|
||||
console.log("Finished downloading to ", result.uri);
|
||||
await saveFileToMediaLibraryAndDeleteOriginal(result.uri, downloadId);
|
||||
const asset = await saveFileToMediaLibraryAndDeleteOriginal(
|
||||
result.uri,
|
||||
downloadId,
|
||||
);
|
||||
return asset;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
@@ -161,7 +166,7 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({
|
||||
const saveFileToMediaLibraryAndDeleteOriginal = async (
|
||||
fileUri: string,
|
||||
downloadId: string,
|
||||
) => {
|
||||
): Promise<Asset | void> => {
|
||||
try {
|
||||
updateDownloadItem(downloadId, { statusText: "Importing" });
|
||||
|
||||
@@ -183,6 +188,7 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({
|
||||
burntOptions: { preset: "done" },
|
||||
native: true,
|
||||
});
|
||||
return asset;
|
||||
} catch (error) {
|
||||
console.error("Error saving file to media library:", error);
|
||||
toastController.show("Download failed", {
|
||||
|
Reference in New Issue
Block a user