@banou/media-player 0.10.46 → 0.10.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -229,31 +229,31 @@ var se = {
229
229
  z.current = B.current, a.setSourceState({ selectedSubtitleTrack: t }), L.current?.selectSubtitleStream(t);
230
230
  let r = V.current.subtitles.find((e) => e.streamIndex === t), i = t === void 0 ? null : u(r) ?? (n ? r?.title?.trim() || "und" : void 0);
231
231
  i !== void 0 && re.current?.(i), i && d(H(), i) && W.current?.(!0);
232
- }, [a, H]), oe = b((e) => {
233
- let t = L.current;
234
- if (!t || O <= 0) {
232
+ }, [a, H]), oe = w(0), se = b((e) => {
233
+ let t = ++oe.current, n = L.current;
234
+ if (!n || O <= 0) {
235
235
  a.seek(e);
236
236
  return;
237
237
  }
238
- let n = typeof window < "u" && window.__mediaPlayerSeekDebug, r = performance.now(), i = !1, o = "prepared", s = () => {
239
- if (!i && (i = !0, L.current === t && (a.seek(e), n))) {
240
- let n = t.videoElement, i = 0;
241
- if (n) for (let t = 0; t < n.buffered.length; t++) n.buffered.start(t) <= e + 1 && e < n.buffered.end(t) && (i = n.buffered.end(t) - e);
242
- console.warn(`[media-player] seek to ${e.toFixed(2)} moved after ${Math.round(performance.now() - r)}ms via ${o}, runway ${i.toFixed(1)}s${o === "deadline" ? " (EXPOSED: moved before its data was ready)" : ""}`);
238
+ let r = typeof window < "u" && window.__mediaPlayerSeekDebug, i = performance.now(), o = !1, s = "prepared", c = () => {
239
+ if (!o && (o = !0, L.current === n && oe.current === t && (a.seek(e), r))) {
240
+ let t = n.videoElement, r = 0;
241
+ if (t) for (let n = 0; n < t.buffered.length; n++) t.buffered.start(n) <= e + 1 && e < t.buffered.end(n) && (r = t.buffered.end(n) - e);
242
+ console.warn(`[media-player] seek to ${e.toFixed(2)} moved after ${Math.round(performance.now() - i)}ms via ${s}, runway ${r.toFixed(1)}s${s === "deadline" ? " (EXPOSED: moved before its data was ready)" : ""}`);
243
243
  }
244
244
  };
245
245
  a.setSourceState({ seekingTo: e });
246
- let c = t.videoElement, l = () => {
247
- c?.removeEventListener("seeked", l), clearTimeout(u), a.setSourceState({ seekingTo: void 0 });
248
- }, u = setTimeout(l, De);
249
- c?.addEventListener("seeked", l);
250
- let d = setTimeout(() => {
251
- o = "deadline", s();
246
+ let l = n.videoElement, u = () => {
247
+ l?.removeEventListener("seeked", u), clearTimeout(d), a.setSourceState({ seekingTo: void 0 });
248
+ }, d = setTimeout(u, De);
249
+ l?.addEventListener("seeked", u);
250
+ let f = setTimeout(() => {
251
+ s = "deadline", c();
252
252
  }, O);
253
- t.prepareSeek(e).catch(() => {}).finally(() => {
254
- clearTimeout(d), s();
253
+ n.prepareSeek(e).catch(() => {}).finally(() => {
254
+ clearTimeout(f), c();
255
255
  });
256
- }, [a, O]), se = b((e) => {
256
+ }, [a, O]), Y = b((e) => {
257
257
  if (typeof e != "number" || B.current === void 0) return;
258
258
  a.setSourceState({ selectedAudioTrack: e }), j({
259
259
  size: B.current,
@@ -261,18 +261,18 @@ var se = {
261
261
  });
262
262
  let t = u(V.current.audio.find((t) => t.streamIndex === e));
263
263
  t !== void 0 && ne.current?.(t);
264
- }, [a]), Y = X((e) => e.setSourceState);
264
+ }, [a]), ce = X((e) => e.setSourceState);
265
265
  S(() => {
266
- Y({
266
+ ce({
267
267
  selectSubtitleTrack: ae,
268
- selectAudioTrack: se,
269
- requestSeek: oe
268
+ selectAudioTrack: Y,
269
+ requestSeek: se
270
270
  });
271
271
  }, [
272
- Y,
272
+ ce,
273
273
  ae,
274
- se,
275
- oe
274
+ Y,
275
+ se
276
276
  ]), S(() => {
277
277
  if (!e || !t || !c || !o) return;
278
278
  let n = !1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@banou/media-player",
3
- "version": "0.10.46",
3
+ "version": "0.10.47",
4
4
  "description": "A video player for containers and codecs the browser cannot play natively, remuxed on the fly",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -197,6 +197,15 @@ export const usePlayback = (
197
197
  if (language && playsIn(playingAudio(), language)) onAlwaysSubtitlesRef.current?.(true)
198
198
  }, [player, playingAudio])
199
199
 
200
+ /*
201
+ * Counts the seeks asked for, so a seek that a newer one replaced never moves the playhead.
202
+ *
203
+ * A newer remuxer task (the newer seek's prepare, or the engine seek its move starts) aborts the older seek's
204
+ * prepare, which then resolves as if its data were in. Firefox 153 landed on the older seek; Chrome 156 moved to it
205
+ * first, into ground with no data (2026-11-21).
206
+ */
207
+ const seeks = useRef(0)
208
+
200
209
  /**
201
210
  * Seek with the data already there, or after the deadline, whichever comes first.
202
211
  *
@@ -209,6 +218,7 @@ export const usePlayback = (
209
218
  * A seek into buffered ground resolves immediately, so scrubbing inside the buffer is unaffected.
210
219
  */
211
220
  const requestSeek = useCallback((time: number) => {
221
+ const seek = ++seeks.current
212
222
  const controller = controllerRef.current
213
223
  // no budget means the feature is off: seek at once and do not spend a read preparing something
214
224
  // nobody is going to wait for
@@ -224,8 +234,8 @@ export const usePlayback = (
224
234
  * quick taps of the arrow keys would have done the same.
225
235
  *
226
236
  * The chrome knows what gesture it is in and now says so by only calling this for settled seeks,
227
- * which is knowledge rather than inference. Rapid calls are safe here anyway: each supersedes
228
- * the last through the engine's seek generation.
237
+ * which is knowledge rather than inference. Rapid calls are safe here anyway: each replaces
238
+ * the last through `seeks`.
229
239
  */
230
240
  /*
231
241
  * A debug trace, off unless asked for.
@@ -245,8 +255,9 @@ export const usePlayback = (
245
255
  const move = () => {
246
256
  if (moved) return
247
257
  moved = true
248
- // the pipeline went away: a new media starts at its own beginning, and a rebuild resumes at this seek itself
249
- if (controllerRef.current !== controller) return
258
+ // a newer seek replaced this one, or the pipeline went away (a new media starts at its own beginning, and a
259
+ // rebuild resumes at this seek itself)
260
+ if (controllerRef.current !== controller || seeks.current !== seek) return
250
261
  player.seek(time)
251
262
  if (debug) {
252
263
  // eslint-disable-next-line no-console