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