Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Sync from GitHub via hub-sync
Browse files
src/components/simple-videos-player.tsx
CHANGED
|
@@ -41,6 +41,17 @@ export const SimpleVideosPlayer = ({
|
|
| 41 |
// If currentTime differs from this, an external source (slider/chart click) changed it.
|
| 42 |
const lastVideoTimeRef = useRef(0);
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
// Initialize video refs array
|
| 45 |
useEffect(() => {
|
| 46 |
videoRefs.current = videoRefs.current.slice(0, videosInfo.length);
|
|
@@ -81,7 +92,7 @@ export const SimpleVideosPlayer = ({
|
|
| 81 |
segmentEnd - THRESHOLDS.VIDEO_SEGMENT_BOUNDARY
|
| 82 |
) {
|
| 83 |
video.currentTime = segmentStart;
|
| 84 |
-
if (index ===
|
| 85 |
setCurrentTime(0);
|
| 86 |
}
|
| 87 |
}
|
|
@@ -102,7 +113,7 @@ export const SimpleVideosPlayer = ({
|
|
| 102 |
} else {
|
| 103 |
const handleEnded = () => {
|
| 104 |
video.currentTime = 0;
|
| 105 |
-
if (index ===
|
| 106 |
setCurrentTime(0);
|
| 107 |
}
|
| 108 |
};
|
|
@@ -128,13 +139,10 @@ export const SimpleVideosPlayer = ({
|
|
| 128 |
}
|
| 129 |
});
|
| 130 |
};
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
firstVisibleIdx,
|
| 136 |
-
setCurrentTime,
|
| 137 |
-
]);
|
| 138 |
|
| 139 |
// Handle play/pause — skip hidden videos
|
| 140 |
useEffect(() => {
|
|
|
|
| 41 |
// If currentTime differs from this, an external source (slider/chart click) changed it.
|
| 42 |
const lastVideoTimeRef = useRef(0);
|
| 43 |
|
| 44 |
+
// Mirror firstVisibleIdx into a ref so the videos-ready effect doesn't have
|
| 45 |
+
// to depend on it. If it did, hiding the first camera would tear the whole
|
| 46 |
+
// effect down and back up, re-attaching `canplaythrough` listeners that
|
| 47 |
+
// never re-fire (the videos are already loaded), leaving readyCount stuck
|
| 48 |
+
// at 0 until the 10s timeout — at which point markReady forces play even
|
| 49 |
+
// if the user paused.
|
| 50 |
+
const firstVisibleIdxRef = useRef(firstVisibleIdx);
|
| 51 |
+
useEffect(() => {
|
| 52 |
+
firstVisibleIdxRef.current = firstVisibleIdx;
|
| 53 |
+
}, [firstVisibleIdx]);
|
| 54 |
+
|
| 55 |
// Initialize video refs array
|
| 56 |
useEffect(() => {
|
| 57 |
videoRefs.current = videoRefs.current.slice(0, videosInfo.length);
|
|
|
|
| 92 |
segmentEnd - THRESHOLDS.VIDEO_SEGMENT_BOUNDARY
|
| 93 |
) {
|
| 94 |
video.currentTime = segmentStart;
|
| 95 |
+
if (index === firstVisibleIdxRef.current) {
|
| 96 |
setCurrentTime(0);
|
| 97 |
}
|
| 98 |
}
|
|
|
|
| 113 |
} else {
|
| 114 |
const handleEnded = () => {
|
| 115 |
video.currentTime = 0;
|
| 116 |
+
if (index === firstVisibleIdxRef.current) {
|
| 117 |
setCurrentTime(0);
|
| 118 |
}
|
| 119 |
};
|
|
|
|
| 139 |
}
|
| 140 |
});
|
| 141 |
};
|
| 142 |
+
// firstVisibleIdx intentionally omitted — we read it via ref so hiding
|
| 143 |
+
// the first camera doesn't reset readiness (see the comment near
|
| 144 |
+
// firstVisibleIdxRef above).
|
| 145 |
+
}, [videosInfo, onVideosReady, setIsPlaying, setCurrentTime]);
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
// Handle play/pause — skip hidden videos
|
| 148 |
useEffect(() => {
|