feat: timeout if media doesn't play after one minute

This commit is contained in:
Adrian Castro
2024-02-20 17:07:35 +01:00
parent 01d2028dbe
commit d42de8cb12

View File

@@ -44,6 +44,7 @@ export const VideoPlayer = () => {
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [resizeMode, setResizeMode] = useState(ResizeMode.CONTAIN); const [resizeMode, setResizeMode] = useState(ResizeMode.CONTAIN);
const [shouldPlay, setShouldPlay] = useState(true); const [shouldPlay, setShouldPlay] = useState(true);
const [hasStartedPlaying, setHasStartedPlaying] = useState(false);
const router = useRouter(); const router = useRouter();
const scale = useSharedValue(1); const scale = useSharedValue(1);
@@ -159,7 +160,17 @@ export const VideoPlayer = () => {
setIsLoading(true); setIsLoading(true);
void initializePlayer(); void initializePlayer();
}, [dismissFullscreenPlayer, router, stream]);
const timeout = setTimeout(() => {
if (!hasStartedPlaying) {
router.back();
}
}, 60000);
return () => {
clearTimeout(timeout);
};
}, [dismissFullscreenPlayer, hasStartedPlaying, router, stream]);
const onVideoLoadStart = () => { const onVideoLoadStart = () => {
setIsLoading(true); setIsLoading(true);
@@ -167,6 +178,7 @@ export const VideoPlayer = () => {
const onReadyForDisplay = () => { const onReadyForDisplay = () => {
setIsLoading(false); setIsLoading(false);
setHasStartedPlaying(true);
}; };
console.log(videoSrc, isLoading); console.log(videoSrc, isLoading);