mirror of
https://github.com/huggingface/lerobot.git
synced 2026-07-24 10:16:09 +00:00
fix race condition
This commit is contained in:
@@ -165,18 +165,24 @@ export const VideosPlayer = ({
|
|||||||
const onCanPlayThrough = () => {
|
const onCanPlayThrough = () => {
|
||||||
videosReadyCount += 1;
|
videosReadyCount += 1;
|
||||||
if (videosReadyCount === videosInfo.length) {
|
if (videosReadyCount === videosInfo.length) {
|
||||||
// Start autoplay when all videos are ready
|
|
||||||
if (typeof onVideosReady === "function") {
|
if (typeof onVideosReady === "function") {
|
||||||
onVideosReady();
|
onVideosReady();
|
||||||
setIsPlaying(true);
|
setIsPlaying(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
videoRefs.current.forEach((video) => {
|
videoRefs.current.forEach((video) => {
|
||||||
if (video) {
|
if (video) {
|
||||||
video.addEventListener("canplaythrough", onCanPlayThrough);
|
// If already ready, call the handler immediately
|
||||||
|
if (video.readyState >= 4) {
|
||||||
|
onCanPlayThrough();
|
||||||
|
} else {
|
||||||
|
video.addEventListener("canplaythrough", onCanPlayThrough);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
videoRefs.current.forEach((video) => {
|
videoRefs.current.forEach((video) => {
|
||||||
if (video) {
|
if (video) {
|
||||||
|
|||||||
Reference in New Issue
Block a user