feat: add timeout handling for loading state with error notification

This commit is contained in:
zimplexing
2025-07-17 22:04:28 +08:00
parent ec949029fa
commit 1f694f9245

View File

@@ -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 (
<ThemedView style={[styles.container, styles.centered]}>
@@ -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