From 1f694f92458878b84f5f4d7d33467ccd5e971ad0 Mon Sep 17 00:00:00 2001 From: zimplexing Date: Thu, 17 Jul 2025 22:04:28 +0800 Subject: [PATCH] feat: add timeout handling for loading state with error notification --- app/play.tsx | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/app/play.tsx b/app/play.tsx index 52a5fef..3a9faf7 100644 --- a/app/play.tsx +++ b/app/play.tsx @@ -96,6 +96,25 @@ export default function PlayScreen() { return () => backHandler.remove(); }, [showControls, setShowControls, router]); + useEffect(() => { + let timeoutId: NodeJS.Timeout | null = null; + + if (isLoading) { + timeoutId = setTimeout(() => { + if (usePlayerStore.getState().isLoading) { + usePlayerStore.setState({ isLoading: false }); + Toast.show({ type: "error", text1: "播放超时,请重试" }); + } + }, 60000); // 1 minute + } + + return () => { + if (timeoutId) { + clearTimeout(timeoutId); + } + }; + }, [isLoading]); + if (!detail) { return ( @@ -122,10 +141,6 @@ export default function PlayScreen() { } usePlayerStore.setState({ isLoading: false }); }} - onError={() => { - usePlayerStore.setState({ isLoading: false }); - Toast.show({ type: "error", text1: "播放失败,请更换源后重试" }); - }} onLoadStart={() => usePlayerStore.setState({ isLoading: true })} useNativeControls={false} shouldPlay