mishig HF Staff commited on
Commit
975bf06
·
verified ·
1 Parent(s): 0f1dfd5

Sync from GitHub via hub-sync

Browse files
src/components/simple-videos-player.tsx CHANGED
@@ -149,11 +149,25 @@ export const SimpleVideosPlayer = ({
149
 
150
  video.addEventListener("timeupdate", handleTimeUpdate);
151
  if (handlePlay) video.addEventListener("play", handlePlay);
152
- if (handleLoadedData)
153
- video.addEventListener("loadeddata", handleLoadedData);
154
  if (handleEnded) video.addEventListener("ended", handleEnded);
155
- if (!info.isSegmented) {
156
- video.addEventListener("canplaythrough", checkReady, { once: true });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  }
158
 
159
  videoEventCleanup.set(video, () => {
 
149
 
150
  video.addEventListener("timeupdate", handleTimeUpdate);
151
  if (handlePlay) video.addEventListener("play", handlePlay);
 
 
152
  if (handleEnded) video.addEventListener("ended", handleEnded);
153
+
154
+ // Already-loaded videos (cached or fast network) will never re-fire
155
+ // canplaythrough / loadeddata after we attach the listener — so check
156
+ // readyState synchronously and mark ready in a microtask. Without this,
157
+ // checkReady wouldn't be called and only the 10s fallback timeout would
158
+ // eventually unfreeze the UI.
159
+ if (info.isSegmented && handleLoadedData) {
160
+ if (video.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA) {
161
+ queueMicrotask(handleLoadedData);
162
+ } else {
163
+ video.addEventListener("loadeddata", handleLoadedData);
164
+ }
165
+ } else if (!info.isSegmented) {
166
+ if (video.readyState >= HTMLMediaElement.HAVE_ENOUGH_DATA) {
167
+ queueMicrotask(checkReady);
168
+ } else {
169
+ video.addEventListener("canplaythrough", checkReady, { once: true });
170
+ }
171
  }
172
 
173
  videoEventCleanup.set(video, () => {