From eaa783824d6e6a75b7ffe88b8c13c8df2f800b6e Mon Sep 17 00:00:00 2001 From: zimplexing Date: Thu, 10 Jul 2025 17:26:12 +0800 Subject: [PATCH] Refactor LivePlayer component to improve loading state handling and error messaging --- app/live.tsx | 20 +-------- components/LivePlayer.tsx | 89 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 86 insertions(+), 23 deletions(-) diff --git a/app/live.tsx b/app/live.tsx index 217e977..d7c06f9 100644 --- a/app/live.tsx +++ b/app/live.tsx @@ -16,7 +16,6 @@ export default function LiveScreen() { const [currentChannelIndex, setCurrentChannelIndex] = useState(0); const [isLoading, setIsLoading] = useState(false); - const [isPlayerLoading, setIsPlayerLoading] = useState(true); const [isChannelListVisible, setIsChannelListVisible] = useState(false); const [channelTitle, setChannelTitle] = useState(null); const titleTimer = useRef(null); @@ -51,14 +50,6 @@ export default function LiveScreen() { loadChannels(); }, []); - const handlePlaybackStatusUpdate = (status: AVPlaybackStatus) => { - if (status.isLoaded) { - setIsPlayerLoading(!status.isPlaying && !status.isBuffering); - } else { - setIsPlayerLoading(true); - } - }; - const showChannelTitle = (title: string) => { setChannelTitle(title); if (titleTimer.current) clearTimeout(titleTimer.current); @@ -98,16 +89,7 @@ export default function LiveScreen() { return ( - - {isPlayerLoading && ( - - - - )} + {}} /> void; } +const PLAYBACK_TIMEOUT = 15000; // 15 seconds + export default function LivePlayer({ streamUrl, channelTitle, onPlaybackStatusUpdate }: LivePlayerProps) { const video = useRef