mirror of
https://github.com/zimplexing/OrionTV.git
synced 2026-05-17 22:17:30 +08:00
Refactor LivePlayer component to improve loading state handling and error messaging
This commit is contained in:
20
app/live.tsx
20
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<string | null>(null);
|
||||
const titleTimer = useRef<NodeJS.Timeout | null>(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 (
|
||||
<ThemedView style={styles.container}>
|
||||
<LivePlayer
|
||||
streamUrl={selectedChannelUrl}
|
||||
channelTitle={channelTitle}
|
||||
onPlaybackStatusUpdate={handlePlaybackStatusUpdate}
|
||||
/>
|
||||
{isPlayerLoading && (
|
||||
<View style={styles.loadingOverlay}>
|
||||
<ActivityIndicator size="large" color="#fff" />
|
||||
</View>
|
||||
)}
|
||||
<LivePlayer streamUrl={selectedChannelUrl} channelTitle={channelTitle} onPlaybackStatusUpdate={() => {}} />
|
||||
<Modal
|
||||
animationType="slide"
|
||||
transparent={true}
|
||||
|
||||
Reference in New Issue
Block a user