@banou/media-player 0.10.47 → 0.10.49

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.
@@ -1,2 +1,2 @@
1
- import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, r as c, s as l, t as u, u as d } from "../engine-wP5Udzzj.js";
1
+ import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, r as c, s as l, t as u, u as d } from "../engine-Cdwc76gM.js";
2
2
  export { i as DEFAULT_BUFFER_SIZE, e as MediaElementError, a as SUBTITLES_OFF, u as createPictureInPicture, d as createSubtitleRenderer, c as createThumbnailGenerator, n as getTimeRanges, s as isMediaElementError, o as pictureInPictureMode, l as startPlayback, t as terminateRemuxer, r as updateSourceBuffer };
@@ -138,7 +138,7 @@ var i = {
138
138
  "pause"
139
139
  ], j = () => k(), M = (e) => {
140
140
  let u = document.createElement("canvas");
141
- r.append(u);
141
+ u.dataset.pending = "", r.append(u);
142
142
  try {
143
143
  h = new n({
144
144
  canvas: u,
@@ -159,7 +159,10 @@ var i = {
159
159
  u.remove(), T(e);
160
160
  return;
161
161
  }
162
- h.setVideo(t).catch(E), h.ready.catch(T);
162
+ let d = h;
163
+ d.setVideo(t).catch(E), d.ready.then(() => {
164
+ h === d && delete u.dataset.pending;
165
+ }, T);
163
166
  for (let e of A) t.addEventListener(e, j);
164
167
  l && D((e) => {
165
168
  m = Promise.resolve(e.addFonts([l])).then(k, T);
@@ -605,7 +608,7 @@ var i = {
605
608
  let { video: t, subtitles: n } = e, r = e.mode ?? K() ?? "window", i = e.maxWidth ?? (r === "burn-in" ? oe : V), a, o, s, c = 0, l = 0, u = 0, d = !1, f = !1, p = !1, m = !1, h, g = () => r === "burn-in" ? !!a : !!a && document.pictureInPictureElement === a.mirror, _ = (e, r) => {
606
609
  r.drawImage(t, 0, 0, e.width, e.height);
607
610
  let i = n.querySelector("canvas");
608
- i && i.width > 0 && i.height > 0 && Math.abs(t.currentTime - u) <= le && r.drawImage(i, 0, 0, e.width, e.height);
611
+ i && !("pending" in i.dataset) && i.width > 0 && i.height > 0 && Math.abs(t.currentTime - u) <= le && r.drawImage(i, 0, 0, e.width, e.height);
609
612
  }, v = () => {
610
613
  let e = Math.min(t.videoWidth || i, i);
611
614
  return {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { c as e, l as t, m as n, n as r, o as i, p as a, r as o, s, t as c, u as l } from "./engine-wP5Udzzj.js";
1
+ import { c as e, l as t, m as n, n as r, o as i, p as a, r as o, s, t as c, u as l } from "./engine-Cdwc76gM.js";
2
2
  import { languageOf as u, playsIn as d, startingTracks as f } from "./language/index.js";
3
3
  import { n as p, r as m, t as h } from "./chapters-EBYXcEml.js";
4
4
  import { Children as g, Fragment as _, createContext as v, isValidElement as y, useCallback as b, useContext as x, useEffect as S, useMemo as C, useRef as w, useState as T, useSyncExternalStore as E } from "react";
@@ -8,8 +8,8 @@ import { definePlayerFeature as M, videoFeatures as N } from "@videojs/core/dom"
8
8
  import { makeRemuxer as P } from "libav-wasm";
9
9
  import { Fragment as F, jsx as I, jsxs as L } from "@emotion/react/jsx-runtime";
10
10
  import { createMediaElementSource as R } from "@banou/ponyfill/web-audio";
11
- import { Captions as z, CaptionsOff as B, Check as V, ChevronLeft as H, ChevronRight as ee, Copy as U, Maximize as te, Minimize as ne, Pause as re, Play as W, RotateCcw as G, Settings as K, TriangleAlert as ie, Volume1 as q, Volume2 as J, VolumeX as ae } from "lucide-react";
12
- import { Tooltip as oe } from "react-tooltip";
11
+ import { Captions as z, CaptionsOff as B, Check as V, ChevronLeft as H, ChevronRight as ee, Copy as te, Maximize as ne, Minimize as re, Pause as ie, Play as U, RotateCcw as W, Settings as G, TriangleAlert as ae, Volume1 as K, Volume2 as q, VolumeX as oe } from "lucide-react";
12
+ import { Tooltip as J } from "react-tooltip";
13
13
  //#region src/lib/react/source-feature.ts
14
14
  var se = {
15
15
  indexes: [],
@@ -200,58 +200,60 @@ var se = {
200
200
  subtitles: []
201
201
  }), H = b(() => V.current.audio.find((e) => e.streamIndex === a.selectedAudioTrack), [a]), ee = w(o);
202
202
  ee.current = o;
203
- let U = {
203
+ let te = {
204
204
  audio: n?.preferredAudioLanguage,
205
205
  original: n?.originalLanguage,
206
206
  subtitles: n?.preferredSubtitleLanguage,
207
207
  alwaysSubtitles: n?.alwaysShowSubtitles
208
- }, te = w(U);
209
- te.current = U;
210
- let ne = w(n?.onPreferredAudioLanguageChange);
211
- ne.current = n?.onPreferredAudioLanguageChange;
212
- let re = w(n?.onPreferredSubtitleLanguageChange);
213
- re.current = n?.onPreferredSubtitleLanguageChange;
214
- let W = w(n?.onAlwaysShowSubtitlesChange);
215
- W.current = n?.onAlwaysShowSubtitlesChange;
216
- let G = w(n?.onSeek);
217
- G.current = n?.onSeek;
218
- let K = w(n?.onPlaybackError);
219
- K.current = n?.onPlaybackError;
220
- let ie = w(r);
221
- ie.current = r;
222
- let q = Q(), J = w(q);
223
- J.current = q, S(() => {
208
+ }, ne = w(te);
209
+ ne.current = te;
210
+ let re = w(n?.onPreferredAudioLanguageChange);
211
+ re.current = n?.onPreferredAudioLanguageChange;
212
+ let ie = w(n?.onPreferredSubtitleLanguageChange);
213
+ ie.current = n?.onPreferredSubtitleLanguageChange;
214
+ let U = w(n?.onAlwaysShowSubtitlesChange);
215
+ U.current = n?.onAlwaysShowSubtitlesChange;
216
+ let W = w(n?.onSeek);
217
+ W.current = n?.onSeek;
218
+ let G = w(n?.onPlaybackError);
219
+ G.current = n?.onPlaybackError;
220
+ let ae = w(r);
221
+ ae.current = r;
222
+ let K = Q(), q = w(K);
223
+ q.current = K, S(() => {
224
224
  let { audio: e, subtitles: t } = V.current;
225
- t.length && a.setSourceState({ subtitleTracks: Ce(t, q) }), e.length && a.setSourceState({ audioTracks: Ce(e, q) });
226
- }, [a, q]);
227
- let ae = b((e) => {
225
+ t.length && a.setSourceState({ subtitleTracks: Ce(t, K) }), e.length && a.setSourceState({ audioTracks: Ce(e, K) });
226
+ }, [a, K]);
227
+ let oe = b((e) => {
228
228
  let t = typeof e == "number" ? e : void 0, n = a.selectedSubtitleTrack === void 0;
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
- i !== void 0 && re.current?.(i), i && d(H(), i) && W.current?.(!0);
232
- }, [a, H]), oe = w(0), se = b((e) => {
233
- let t = ++oe.current, n = L.current;
234
- if (!n || O <= 0) {
235
- a.seek(e);
231
+ i !== void 0 && ie.current?.(i), i && d(H(), i) && U.current?.(!0);
232
+ }, [a, H]), J = w(0), se = b((e, t = !1) => {
233
+ let n = ++J.current, r = L.current;
234
+ if (!r || O <= 0 || t) {
235
+ a.setSourceState({ seekingTo: void 0 }), a.seek(e);
236
236
  return;
237
237
  }
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)" : ""}`);
238
+ let i = typeof window < "u" && window.__mediaPlayerSeekDebug, o = performance.now(), s = !1, c = "prepared", l = () => {
239
+ if (!s && (s = !0, L.current === r && J.current === n && (a.seek(e), i))) {
240
+ let t = r.videoElement, n = 0;
241
+ if (t) for (let r = 0; r < t.buffered.length; r++) t.buffered.start(r) <= e + 1 && e < t.buffered.end(r) && (n = t.buffered.end(r) - e);
242
+ console.warn(`[media-player] seek to ${e.toFixed(2)} moved after ${Math.round(performance.now() - o)}ms via ${c}, runway ${n.toFixed(1)}s${c === "deadline" ? " (EXPOSED: moved before its data was ready)" : ""}`);
243
243
  }
244
244
  };
245
245
  a.setSourceState({ seekingTo: e });
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();
246
+ let u = r.videoElement, d = () => {
247
+ u?.removeEventListener("seeked", f), clearTimeout(p), J.current === n && a.setSourceState({ seekingTo: void 0 });
248
+ }, f = () => {
249
+ s && d();
250
+ }, p = setTimeout(d, De);
251
+ u?.addEventListener("seeked", f);
252
+ let m = setTimeout(() => {
253
+ c = "deadline", l();
252
254
  }, O);
253
- n.prepareSeek(e).catch(() => {}).finally(() => {
254
- clearTimeout(f), c();
255
+ r.prepareSeek(e).catch(() => {}).finally(() => {
256
+ clearTimeout(m), l();
255
257
  });
256
258
  }, [a, O]), Y = b((e) => {
257
259
  if (typeof e != "number" || B.current === void 0) return;
@@ -260,17 +262,17 @@ var se = {
260
262
  streamIndex: e
261
263
  });
262
264
  let t = u(V.current.audio.find((t) => t.streamIndex === e));
263
- t !== void 0 && ne.current?.(t);
265
+ t !== void 0 && re.current?.(t);
264
266
  }, [a]), ce = X((e) => e.setSourceState);
265
267
  S(() => {
266
268
  ce({
267
- selectSubtitleTrack: ae,
269
+ selectSubtitleTrack: oe,
268
270
  selectAudioTrack: Y,
269
271
  requestSeek: se
270
272
  });
271
273
  }, [
272
274
  ce,
273
- ae,
275
+ oe,
274
276
  Y,
275
277
  se
276
278
  ]), S(() => {
@@ -317,7 +319,7 @@ var se = {
317
319
  }, console.warn(`the media element failed; rebuilding the pipeline${n ? ` in ${n}ms` : ""}`, e), I.current && clearTimeout(I.current), I.current = setTimeout(() => P((e) => e + 1), n);
318
320
  return;
319
321
  }
320
- console.error("playback failed", e), a.setSourceState({ playbackError: e }), K.current?.(e);
322
+ console.error("playback failed", e), a.setSourceState({ playbackError: e }), G.current?.(e);
321
323
  };
322
324
  return (async () => {
323
325
  try {
@@ -337,7 +339,7 @@ var se = {
337
339
  cjkFontUrl: x,
338
340
  bufferSize: C,
339
341
  audioStreamIndex: M,
340
- chooseAudioStream: (e) => e[f(e, [], te.current).audio]?.streamIndex,
342
+ chooseAudioStream: (e) => e[f(e, [], ne.current).audio]?.streamIndex,
341
343
  onReady: () => {
342
344
  if (n) return;
343
345
  a.setSourceState({ ready: !0 });
@@ -348,20 +350,20 @@ var se = {
348
350
  onRecovered: () => {
349
351
  n || a.setSourceState({ playbackError: null });
350
352
  },
351
- onSeek: (e) => G.current?.(e),
352
- onOutput: (e) => ie.current?.(e),
353
+ onSeek: (e) => W.current?.(e),
354
+ onOutput: (e) => ae.current?.(e),
353
355
  onSubtitleStreams: (e) => {
354
356
  if (n) return;
355
357
  V.current.subtitles = e;
356
- let t = H(), r = f(t ? [t] : [], e, te.current).subtitles;
358
+ let t = H(), r = f(t ? [t] : [], e, ne.current).subtitles;
357
359
  a.setSourceState({
358
- subtitleTracks: Ce(e, J.current),
360
+ subtitleTracks: Ce(e, q.current),
359
361
  ...z.current === c ? {} : { selectedSubtitleTrack: r === null ? void 0 : e[Math.max(r, 0)]?.streamIndex }
360
362
  });
361
363
  },
362
364
  onAudioStreams: (e, t) => {
363
365
  n || (V.current.audio = e, a.setSourceState({
364
- audioTracks: Ce(e, J.current),
366
+ audioTracks: Ce(e, q.current),
365
367
  selectedAudioTrack: t
366
368
  }));
367
369
  }
@@ -707,7 +709,7 @@ var se = {
707
709
  }, g = 0, _ = /* @__PURE__ */ new Map(), v = (e, t) => new Promise((n) => _.set(`${e}:${t}`, n)), y = -1;
708
710
  p.onmessage = ({ data: e }) => {
709
711
  if (e.type === "unsupported") {
710
- ne();
712
+ re();
711
713
  return;
712
714
  }
713
715
  e.spans && ((JSON.stringify(e.spans) !== JSON.stringify(h.spans) || e.end !== h.end) && g++, h = {
@@ -825,7 +827,7 @@ var se = {
825
827
  }
826
828
  e(B), B = void 0;
827
829
  }
828
- }, U = () => {}, te = (e, t) => {
830
+ }, te = () => {}, ne = (e, t) => {
829
831
  let n = !1, r = (e) => {
830
832
  n && p.postMessage({
831
833
  type: "end",
@@ -833,7 +835,7 @@ var se = {
833
835
  finished: e
834
836
  }), n = !1;
835
837
  };
836
- U = e.attach(t, (e, t) => {
838
+ te = e.attach(t, (e, t) => {
837
839
  if (e.type === "init") {
838
840
  r(!1);
839
841
  let t = e.data.slice(0);
@@ -860,22 +862,22 @@ var se = {
860
862
  }, [t]);
861
863
  }
862
864
  });
863
- }, ne = () => {
865
+ }, re = () => {
864
866
  if (!a) {
865
867
  a = !0, f(!0), l(), clearInterval(C);
866
868
  for (let e of w) n.removeEventListener(e, x);
867
- n.removeEventListener("seeking", R), n.removeEventListener("seeked", z), n.removeEventListener("timeupdate", z), U(), B && e(B), p.terminate(), t.port.postMessage({ analysis: null });
869
+ n.removeEventListener("seeking", R), n.removeEventListener("seeked", z), n.removeEventListener("timeupdate", z), te(), B && e(B), p.terminate(), t.port.postMessage({ analysis: null });
868
870
  for (let e of _.values()) e(h);
869
871
  _.clear();
870
872
  }
871
873
  };
872
- return "tap" in i ? te(i.tap, i.audioStreamIndex) : ee(i).catch((e) => {
873
- a || (console.warn("[media-player] the volume normalizer cannot analyse ahead:", e), ne());
874
+ return "tap" in i ? ne(i.tap, i.audioStreamIndex) : ee(i).catch((e) => {
875
+ a || (console.warn("[media-player] the volume normalizer cannot analyse ahead:", e), re());
874
876
  }), S(), {
875
877
  update: (e) => {
876
878
  o = e, f(!1);
877
879
  },
878
- stop: ne
880
+ stop: re
879
881
  };
880
882
  }, nt = (e, t, n, r, i) => {
881
883
  let a = w(null), [o, s] = T(!1), [c, l] = T(null);
@@ -1156,7 +1158,7 @@ var se = {
1156
1158
  "data-tooltip-delay-hide": i,
1157
1159
  "data-tooltip-place": o,
1158
1160
  children: n
1159
- }), !s && /* @__PURE__ */ I(oe, {
1161
+ }), !s && /* @__PURE__ */ I(J, {
1160
1162
  ref: u,
1161
1163
  css: yt(c),
1162
1164
  id: e,
@@ -1460,7 +1462,7 @@ var se = {
1460
1462
  B.current !== "touch" && E(z(e.clientX));
1461
1463
  }, ee = () => {
1462
1464
  _.current && E(void 0);
1463
- }, U = (e) => r ? e / r * 100 : 0, te = (e, t, n) => {
1465
+ }, te = (e) => r ? e / r * 100 : 0, ne = (e, t, n) => {
1464
1466
  let r = Number((n - t).toFixed(4)), i = t * 100;
1465
1467
  return /* @__PURE__ */ I("div", {
1466
1468
  className: "loaded-part",
@@ -1469,10 +1471,10 @@ var se = {
1469
1471
  marginLeft: `${i}%`
1470
1472
  }
1471
1473
  }, e);
1472
- }, ne = C(() => i === void 0 ? r ? o.map(([e, t], n) => te(n, e / r, t / r)) : [] : a?.map((e, t) => {
1474
+ }, re = C(() => i === void 0 ? r ? o.map(([e, t], n) => ne(n, e / r, t / r)) : [] : a?.map((e, t) => {
1473
1475
  if (!i || !r) return null;
1474
1476
  let n = s.filter((t) => e.startByteOffset <= t.pos && t.pos <= e.endByteOffset), a = n.at(0), o = n.at(-1);
1475
- return !a || !o ? null : te(t, a.timestamp / r, o.timestamp / r);
1477
+ return !a || !o ? null : ne(t, a.timestamp / r, o.timestamp / r);
1476
1478
  }) ?? [], [
1477
1479
  r,
1478
1480
  i,
@@ -1481,14 +1483,15 @@ var se = {
1481
1483
  a?.map(({ startByteOffset: e, endByteOffset: t }) => `${e}/${t}`).join(",")
1482
1484
  ]);
1483
1485
  S(() => {
1484
- v !== void 0 && r && N && M.current && e.seek(v * r);
1486
+ v !== void 0 && r && N && M.current && (n ? n(v * r, !0) : e.seek(v * r));
1485
1487
  }, [
1486
1488
  e,
1489
+ n,
1487
1490
  N,
1488
1491
  v,
1489
1492
  r
1490
1493
  ]);
1491
- let re = C(() => {
1494
+ let ie = C(() => {
1492
1495
  if (!r) return 0;
1493
1496
  if (N && v !== void 0) return v;
1494
1497
  let e = f ?? t;
@@ -1499,22 +1502,22 @@ var se = {
1499
1502
  N,
1500
1503
  v,
1501
1504
  f
1502
- ]), W = C(() => p(d, r), [d, r]), G = W.length > 0, K = C(() => {
1503
- if (!G || b === void 0 || !r) return -1;
1504
- let e = b / r * 100, t = W.findIndex((t, n) => n < W.length - 1 && e >= t && e < W[n + 1]);
1505
- return t >= 0 ? t : W.length - 2;
1505
+ ]), U = C(() => p(d, r), [d, r]), W = U.length > 0, G = C(() => {
1506
+ if (!W || b === void 0 || !r) return -1;
1507
+ let e = b / r * 100, t = U.findIndex((t, n) => n < U.length - 1 && e >= t && e < U[n + 1]);
1508
+ return t >= 0 ? t : U.length - 2;
1506
1509
  }, [
1507
- G,
1508
1510
  W,
1511
+ U,
1509
1512
  b,
1510
1513
  r
1511
- ]), ie = C(() => G ? m(W, (e) => e !== K) : void 0, [
1512
- G,
1514
+ ]), ae = C(() => W ? m(U, (e) => e !== G) : void 0, [
1513
1515
  W,
1514
- K
1515
- ]), q = C(() => K >= 0 ? m(W, (e) => e === K) : void 0, [W, K]), J = C(() => {
1516
+ U,
1517
+ G
1518
+ ]), K = C(() => G >= 0 ? m(U, (e) => e === G) : void 0, [U, G]), q = C(() => {
1516
1519
  if (b !== void 0) return d.find(({ start: e, end: t }) => e <= b && b < t);
1517
- }, [d, b]), ae = C(() => {
1520
+ }, [d, b]), oe = C(() => {
1518
1521
  if (b) {
1519
1522
  if (l) return l(b);
1520
1523
  if (c.length) return c.find(({ startTime: e, endTime: t }) => e <= b && b < t);
@@ -1523,20 +1526,20 @@ var se = {
1523
1526
  c,
1524
1527
  l,
1525
1528
  b
1526
- ]), oe = (e, t) => /* @__PURE__ */ L("div", {
1529
+ ]), J = (e, t) => /* @__PURE__ */ L("div", {
1527
1530
  className: e ? `track ${e}` : "track",
1528
1531
  style: t ? { maskImage: t } : void 0,
1529
1532
  children: [
1530
1533
  /* @__PURE__ */ I("div", { className: "background-bar" }),
1531
1534
  /* @__PURE__ */ I("div", {
1532
1535
  className: "loaded",
1533
- children: ne
1536
+ children: re
1534
1537
  }),
1535
1538
  /* @__PURE__ */ I("div", {
1536
1539
  className: "play-container",
1537
1540
  children: /* @__PURE__ */ I("div", {
1538
1541
  className: "play",
1539
- style: { transform: `scaleX(${re})` }
1542
+ style: { transform: `scaleX(${ie})` }
1540
1543
  })
1541
1544
  })
1542
1545
  ]
@@ -1547,31 +1550,31 @@ var se = {
1547
1550
  className: [
1548
1551
  "progress-bar",
1549
1552
  N ? "dragging" : "",
1550
- G ? "segmented" : ""
1553
+ W ? "segmented" : ""
1551
1554
  ].filter(Boolean).join(" "),
1552
1555
  onPointerDown: V,
1553
1556
  onPointerMove: V,
1554
1557
  onMouseMove: H,
1555
1558
  onMouseOut: ee,
1556
1559
  children: [
1557
- oe(void 0, ie),
1560
+ J(void 0, ae),
1558
1561
  b ? /* @__PURE__ */ L("div", {
1559
1562
  className: "cursor-time",
1560
1563
  style: {
1561
- left: J ? `clamp(var(--thumbnail-half), ${U(b)}%, calc(100% - var(--thumbnail-half)))` : `clamp(calc(3 * var(--mp-unit)), ${U(b)}%, calc(100% - calc(3 * var(--mp-unit))))`,
1562
- maxWidth: J ? "var(--thumbnail-width)" : void 0
1564
+ left: q ? `clamp(var(--thumbnail-half), ${te(b)}%, calc(100% - var(--thumbnail-half)))` : `clamp(calc(3 * var(--mp-unit)), ${te(b)}%, calc(100% - calc(3 * var(--mp-unit))))`,
1565
+ maxWidth: q ? "var(--thumbnail-width)" : void 0
1563
1566
  },
1564
1567
  children: [/* @__PURE__ */ I("span", {
1565
1568
  className: "cursor-time-value",
1566
1569
  children: _t(b)
1567
- }), J ? /* @__PURE__ */ I("span", {
1570
+ }), q ? /* @__PURE__ */ I("span", {
1568
1571
  className: "chapter-title",
1569
- children: J.title
1572
+ children: q.title
1570
1573
  }) : void 0]
1571
1574
  }) : void 0,
1572
1575
  /* @__PURE__ */ I("div", { className: "progress" }),
1573
1576
  /* @__PURE__ */ I("div", { className: "hover" }),
1574
- q ? oe("focus", q) : void 0,
1577
+ K ? J("focus", K) : void 0,
1575
1578
  /* @__PURE__ */ I("div", { className: "scrubber" }),
1576
1579
  /* @__PURE__ */ I("div", {
1577
1580
  className: "padding",
@@ -1582,8 +1585,8 @@ var se = {
1582
1585
  }),
1583
1586
  /* @__PURE__ */ I("div", {
1584
1587
  className: "thumbnail",
1585
- style: { left: `clamp(var(--thumbnail-half), ${U(b ?? 1)}%, calc(100% - var(--thumbnail-half)))` },
1586
- children: ae?.url ? /* @__PURE__ */ I("img", { src: ae.url }) : void 0
1588
+ style: { left: `clamp(var(--thumbnail-half), ${te(b ?? 1)}%, calc(100% - var(--thumbnail-half)))` },
1589
+ children: oe?.url ? /* @__PURE__ */ I("img", { src: oe.url }) : void 0
1587
1590
  })
1588
1591
  ]
1589
1592
  });
@@ -1939,7 +1942,7 @@ ${Nt}
1939
1942
  onClick: i,
1940
1943
  "aria-label": u,
1941
1944
  "aria-expanded": r,
1942
- children: /* @__PURE__ */ I(ie, { className: "alert-triangle" })
1945
+ children: /* @__PURE__ */ I(ae, { className: "alert-triangle" })
1943
1946
  }),
1944
1947
  toolTipText: /* @__PURE__ */ I("span", { children: u })
1945
1948
  }), r && /* @__PURE__ */ L("div", {
@@ -1951,7 +1954,7 @@ ${Nt}
1951
1954
  type: "button",
1952
1955
  onClick: l,
1953
1956
  "aria-label": t(a.copyErrors),
1954
- children: [I(s ? V : U, {}), /* @__PURE__ */ I("span", { children: t(s ? a.copied : a.copy) })]
1957
+ children: [I(s ? V : te, {}), /* @__PURE__ */ I("span", { children: t(s ? a.copied : a.copy) })]
1955
1958
  })]
1956
1959
  }), e.map((e, r) => /* @__PURE__ */ L("div", {
1957
1960
  className: "entry no-hover",
@@ -2197,7 +2200,7 @@ ${Nt}
2197
2200
  onClick: m,
2198
2201
  "aria-label": t(a.settings),
2199
2202
  "aria-expanded": p,
2200
- children: /* @__PURE__ */ I(K, {})
2203
+ children: /* @__PURE__ */ I(G, {})
2201
2204
  }),
2202
2205
  toolTipText: /* @__PURE__ */ I("span", { children: t(a.settings) })
2203
2206
  }),
@@ -2499,7 +2502,7 @@ ${Nt}
2499
2502
  ref: e,
2500
2503
  "aria-label": n(a.mute),
2501
2504
  "aria-pressed": i || r === 0,
2502
- children: I(i || r === 0 ? ae : r <= .5 ? q : J, {
2505
+ children: I(i || r === 0 ? oe : r <= .5 ? K : q, {
2503
2506
  size: 18,
2504
2507
  color: "#fff"
2505
2508
  })
@@ -2754,7 +2757,7 @@ ${Nt}
2754
2757
  type: "button",
2755
2758
  onClick: () => r.togglePaused(),
2756
2759
  "aria-label": i(j ? a.replay : o ? a.play : a.pause),
2757
- children: I(j ? G : o ? W : re, {})
2760
+ children: I(j ? W : o ? U : ie, {})
2758
2761
  }),
2759
2762
  toolTipText: /* @__PURE__ */ I("span", { children: i(j ? a.replayKey : o ? a.playKey : a.pauseKey) })
2760
2763
  }),
@@ -2814,7 +2817,7 @@ ${Nt}
2814
2817
  onClick: P,
2815
2818
  "aria-label": i(a.fullScreen),
2816
2819
  "aria-pressed": d,
2817
- children: I(d ? ne : te, {})
2820
+ children: I(d ? re : ne, {})
2818
2821
  }),
2819
2822
  toolTipText: /* @__PURE__ */ I("span", { children: i(d ? a.exitFullScreenKey : a.fullScreenKey) })
2820
2823
  })
@@ -3182,7 +3185,7 @@ ${Nt}
3182
3185
  }
3183
3186
  })), B = D === !0 ? {} : D || void 0, V = w(B);
3184
3187
  V.current = B;
3185
- let H = B ? B.id : void 0, ee = B ? B.origin : void 0, U = B ? B.channel : void 0;
3188
+ let H = B ? B.id : void 0, ee = B ? B.origin : void 0, te = B ? B.channel : void 0;
3186
3189
  S(() => {
3187
3190
  if (!D || !E) return;
3188
3191
  let e, t = !1;
@@ -3199,35 +3202,35 @@ ${Nt}
3199
3202
  !!D,
3200
3203
  H,
3201
3204
  ee,
3202
- U
3205
+ te
3203
3206
  ]);
3204
- let te = X((e) => e.chapters), ne = JSON.stringify(te);
3207
+ let ne = X((e) => e.chapters), re = JSON.stringify(ne);
3205
3208
  S(() => {
3206
- z.chapters = te, z.endingOffered = M, z.dispatchEvent(new Event("chapterschange"));
3207
- }, [ne, M]);
3208
- let re = e.autoplayNext;
3209
+ z.chapters = ne, z.endingOffered = M, z.dispatchEvent(new Event("chapterschange"));
3210
+ }, [re, M]);
3211
+ let ie = e.autoplayNext;
3209
3212
  S(() => {
3210
- P === null && R(re);
3211
- }, [re, P]);
3212
- let W = w(e.onAutoplayNextChange);
3213
- W.current = e.onAutoplayNextChange, S(() => {
3213
+ P === null && R(ie);
3214
+ }, [ie, P]);
3215
+ let U = w(e.onAutoplayNextChange);
3216
+ U.current = e.onAutoplayNextChange, S(() => {
3214
3217
  z.autoplayNext = L ?? null, z.dispatchEvent(new Event("autoplaynextchange"));
3215
3218
  }, [L]);
3216
- let G = e.fullscreen ?? (O === null ? void 0 : {
3219
+ let W = e.fullscreen ?? (O === null ? void 0 : {
3217
3220
  active: O,
3218
3221
  request: () => z.dispatchEvent(new Event("fullscreenrequest"))
3219
- }), K = C(() => rt(), [o]);
3220
- Ae(v, b, r, h ? K.push : void 0);
3221
- let ie = r?.normalizeVolume ?? !0, [q, J] = T(ie);
3222
+ }), G = C(() => rt(), [o]);
3223
+ Ae(v, b, r, h ? G.push : void 0);
3224
+ let ae = r?.normalizeVolume ?? !0, [K, q] = T(ae);
3222
3225
  S(() => {
3223
- J(ie);
3224
- }, [ie]);
3225
- let ae = w(r?.onNormalizeVolumeChange);
3226
- ae.current = r?.onNormalizeVolumeChange;
3227
- let oe = r?.normalizerWorkletUrl, se = w(p ?? f);
3226
+ q(ae);
3227
+ }, [ae]);
3228
+ let oe = w(r?.onNormalizeVolumeChange);
3229
+ oe.current = r?.onNormalizeVolumeChange;
3230
+ let J = r?.normalizerWorkletUrl, se = w(p ?? f);
3228
3231
  se.current = p ?? f;
3229
- let Y = X((e) => e.selectedAudioTrack), ce = !!f, { refused: le } = nt(v, oe, q, C(() => ce && o && c && l && typeof Y == "number" && Y >= 0 ? h ? {
3230
- tap: K,
3232
+ let Y = X((e) => e.selectedAudioTrack), ce = !!f, { refused: le } = nt(v, J, K, C(() => ce && o && c && l && typeof Y == "number" && Y >= 0 ? h ? {
3233
+ tap: G,
3231
3234
  audioStreamIndex: Y
3232
3235
  } : {
3233
3236
  read: (e, t) => se.current(e, t),
@@ -3242,16 +3245,16 @@ ${Nt}
3242
3245
  l,
3243
3246
  Y,
3244
3247
  h,
3245
- K
3246
- ]), C(() => s?.map(({ startByteOffset: e, endByteOffset: t }) => [e, t]), [s?.map(({ startByteOffset: e, endByteOffset: t }) => `${e}-${t}`).join(",")])), ue = C(() => oe && typeof AudioWorkletNode == "function" ? {
3247
- enabled: q,
3248
+ G
3249
+ ]), C(() => s?.map(({ startByteOffset: e, endByteOffset: t }) => [e, t]), [s?.map(({ startByteOffset: e, endByteOffset: t }) => `${e}-${t}`).join(",")])), ue = C(() => J && typeof AudioWorkletNode == "function" ? {
3250
+ enabled: K,
3248
3251
  available: !le,
3249
3252
  setEnabled: (e) => {
3250
- J(e), ae.current?.(e);
3253
+ q(e), oe.current?.(e);
3251
3254
  }
3252
3255
  } : null, [
3253
- oe,
3254
- q,
3256
+ J,
3257
+ K,
3255
3258
  le
3256
3259
  ]), { thumbnails: de, requestThumbnail: fe } = ze({
3257
3260
  publicPath: c,
@@ -3298,7 +3301,7 @@ ${Nt}
3298
3301
  Z({ autoplayNext: L === void 0 ? null : {
3299
3302
  enabled: L,
3300
3303
  setEnabled: (e) => {
3301
- R(e), W.current?.(e);
3304
+ R(e), U.current?.(e);
3302
3305
  }
3303
3306
  } });
3304
3307
  }, [Z, L]), S(() => {
@@ -3356,7 +3359,7 @@ ${Nt}
3356
3359
  overlay: e.overlay,
3357
3360
  controls: e.controls,
3358
3361
  shortcuts: e.shortcuts,
3359
- fullscreen: G,
3362
+ fullscreen: W,
3360
3363
  endingOffered: M,
3361
3364
  children: t
3362
3365
  });
@@ -25,7 +25,7 @@ export declare const Player: import("@videojs/react").CreatePlayerResult<import(
25
25
  burnedInSubtitles: boolean;
26
26
  volumeNormalizer: import("./source-feature").VolumeNormalizerControl | null;
27
27
  autoplayNext: import("./source-feature").AutoplayNextControl | null;
28
- requestSeek?: (time: number) => void;
28
+ requestSeek?: (time: number, now?: boolean) => void;
29
29
  stepFrame?: (direction: 1 | -1) => void;
30
30
  playbackError: unknown;
31
31
  playbackErrors: import("./source-feature").PlaybackErrorEntry[];
@@ -221,10 +221,13 @@ export type SourceState = {
221
221
  * Waiting is bounded by a deadline, so a source that cannot answer in time costs that deadline and
222
222
  * not the whole read.
223
223
  *
224
+ * `now` moves at once without waiting, as a scrub following the pointer does. Any call replaces a seek still
225
+ * waiting for its data.
226
+ *
224
227
  * Undefined for a media this player does not own, where there is no pipeline to prepare and the
225
228
  * caller should seek directly.
226
229
  */
227
- requestSeek?: (time: number) => void;
230
+ requestSeek?: (time: number, now?: boolean) => void;
228
231
  /**
229
232
  * One frame back or forward, pausing first. Undefined for a media whose frames this document cannot see, unless its
230
233
  * host steps it (the remote arm's `stepFrame`).
@@ -375,10 +378,13 @@ export declare const sourceFeature: import("@videojs/react").PlayerFeature<{
375
378
  * Waiting is bounded by a deadline, so a source that cannot answer in time costs that deadline and
376
379
  * not the whole read.
377
380
  *
381
+ * `now` moves at once without waiting, as a scrub following the pointer does. Any call replaces a seek still
382
+ * waiting for its data.
383
+ *
378
384
  * Undefined for a media this player does not own, where there is no pipeline to prepare and the
379
385
  * caller should seek directly.
380
386
  */
381
- requestSeek?: (time: number) => void;
387
+ requestSeek?: (time: number, now?: boolean) => void;
382
388
  /**
383
389
  * One frame back or forward, pausing first. Undefined for a media whose frames this document cannot see, unless its
384
390
  * host steps it (the remote arm's `stepFrame`).
@@ -896,7 +896,10 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
896
896
  this.ring.fill(0)
897
897
  this.ringSum = 0
898
898
  this.ringFill = 0
899
- if (this.offset !== null) this.doubt = true
899
+ if (this.offset !== null) {
900
+ this.doubt = true
901
+ if (data.reset === 'seek') this.jumped = true
902
+ }
900
903
  }
901
904
  if (data?.reset === 'source') {
902
905
  this.hist.fill(0)
@@ -930,6 +933,7 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
930
933
  this.candidate = null
931
934
  this.search = null
932
935
  this.doubt = false
936
+ this.jumped = false
933
937
  this.model = null
934
938
  this.settling = []
935
939
  this.liveCount = 0
@@ -945,16 +949,18 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
945
949
  pair({ media, ctx, rate, paused }) {
946
950
  const frame = ctx * sampleRate
947
951
  const model = this.model
952
+ const previous = model ? this.mediaAt(frame) : media
953
+ if (this.offset !== null && !(Math.abs(media - previous) <= 0.025)) this.jumped = true
948
954
  if (paused) {
949
955
  // More than 25 ms from where the clock had it, the media is where the pair says: a seek moved it, its audio
950
956
  // already playing (10 to 27 ms after the move in Chrome 155, where the main thread once took 52 ms to say so,
951
957
  // 2026-10-30), or a pause was told late. The seek's reset, posted on the same event, is what puts it in doubt.
952
- const held = model && !model.paused ? this.mediaAt(frame) : media
958
+ const held = model && !model.paused ? previous : media
953
959
  this.model = { paused: true, media: Math.abs(media - held) <= 0.025 ? held : media }
954
960
  this.liveCount = 0
955
961
  return
956
962
  }
957
- const predicted = model && !model.paused && model.rate === rate ? model.media + (frame - model.frame) * rate / sampleRate : NaN
963
+ const predicted = model && !model.paused && model.rate === rate ? previous : NaN
958
964
  if (!(Math.abs(media - predicted) <= 0.025)) {
959
965
  this.model = { frame, media, rate }
960
966
  this.settling = []
@@ -1281,16 +1287,21 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
1281
1287
  this.gainLine[at] = gain
1282
1288
 
1283
1289
  if (ahead) {
1284
- // at most 0.2 dB a sample, so a change of mode cannot click; the cut itself moves slower
1290
+ // at most 0.2 dB a sample, so a change of mode cannot click; the cut itself moves slower.
1291
+ // After a seek jump, a deeper cut takes effect at once so the first 1 to 2 ms of a loud sound are not left uncut.
1285
1292
  let wantedDb = exact ? this.cutAt(this.mediaAt(start + i - delay) + this.offset) : held
1286
1293
  if (!(wantedDb <= 0)) wantedDb = this.aheadDb
1287
1294
  if (wantedDb > this.aheadDb + 0.2) wantedDb = this.aheadDb + 0.2
1288
- else if (wantedDb < this.aheadDb - 0.2) wantedDb = this.aheadDb - 0.2
1295
+ else if (!this.jumped && wantedDb < this.aheadDb - 0.2) wantedDb = this.aheadDb - 0.2
1289
1296
  this.aheadDb = wantedDb
1297
+ this.jumped = false
1290
1298
  this.handover = Math.min(1, this.handover + handoverStep)
1291
1299
  } else {
1292
1300
  this.handover = Math.max(0, this.handover - handoverStep)
1293
- if (this.handover === 0) this.aheadDb = liveDb
1301
+ if (this.handover === 0) {
1302
+ this.aheadDb = liveDb
1303
+ this.jumped = false
1304
+ }
1294
1305
  }
1295
1306
  this.mix += Math.max(-crossfadeStep, Math.min(crossfadeStep, target - this.mix))
1296
1307
  const db = (liveDb + (this.aheadDb - liveDb) * this.handover) * this.mix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@banou/media-player",
3
- "version": "0.10.47",
3
+ "version": "0.10.49",
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",
@@ -54,7 +54,7 @@
54
54
  "@videojs/react": "10.0.0-beta.26",
55
55
  "ass-compiler": "^0.1.16",
56
56
  "jassub": "^2.5.37",
57
- "libav-wasm": "^0.8.14",
57
+ "libav-wasm": "^0.8.16",
58
58
  "lucide-react": "^0.536.0",
59
59
  "osra": "^0.6.12",
60
60
  "react-tooltip": "^5.28.0"
@@ -896,7 +896,10 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
896
896
  this.ring.fill(0)
897
897
  this.ringSum = 0
898
898
  this.ringFill = 0
899
- if (this.offset !== null) this.doubt = true
899
+ if (this.offset !== null) {
900
+ this.doubt = true
901
+ if (data.reset === 'seek') this.jumped = true
902
+ }
900
903
  }
901
904
  if (data?.reset === 'source') {
902
905
  this.hist.fill(0)
@@ -930,6 +933,7 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
930
933
  this.candidate = null
931
934
  this.search = null
932
935
  this.doubt = false
936
+ this.jumped = false
933
937
  this.model = null
934
938
  this.settling = []
935
939
  this.liveCount = 0
@@ -945,16 +949,18 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
945
949
  pair({ media, ctx, rate, paused }) {
946
950
  const frame = ctx * sampleRate
947
951
  const model = this.model
952
+ const previous = model ? this.mediaAt(frame) : media
953
+ if (this.offset !== null && !(Math.abs(media - previous) <= 0.025)) this.jumped = true
948
954
  if (paused) {
949
955
  // More than 25 ms from where the clock had it, the media is where the pair says: a seek moved it, its audio
950
956
  // already playing (10 to 27 ms after the move in Chrome 155, where the main thread once took 52 ms to say so,
951
957
  // 2026-10-30), or a pause was told late. The seek's reset, posted on the same event, is what puts it in doubt.
952
- const held = model && !model.paused ? this.mediaAt(frame) : media
958
+ const held = model && !model.paused ? previous : media
953
959
  this.model = { paused: true, media: Math.abs(media - held) <= 0.025 ? held : media }
954
960
  this.liveCount = 0
955
961
  return
956
962
  }
957
- const predicted = model && !model.paused && model.rate === rate ? model.media + (frame - model.frame) * rate / sampleRate : NaN
963
+ const predicted = model && !model.paused && model.rate === rate ? previous : NaN
958
964
  if (!(Math.abs(media - predicted) <= 0.025)) {
959
965
  this.model = { frame, media, rate }
960
966
  this.settling = []
@@ -1281,16 +1287,21 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
1281
1287
  this.gainLine[at] = gain
1282
1288
 
1283
1289
  if (ahead) {
1284
- // at most 0.2 dB a sample, so a change of mode cannot click; the cut itself moves slower
1290
+ // at most 0.2 dB a sample, so a change of mode cannot click; the cut itself moves slower.
1291
+ // After a seek jump, a deeper cut takes effect at once so the first 1 to 2 ms of a loud sound are not left uncut.
1285
1292
  let wantedDb = exact ? this.cutAt(this.mediaAt(start + i - delay) + this.offset) : held
1286
1293
  if (!(wantedDb <= 0)) wantedDb = this.aheadDb
1287
1294
  if (wantedDb > this.aheadDb + 0.2) wantedDb = this.aheadDb + 0.2
1288
- else if (wantedDb < this.aheadDb - 0.2) wantedDb = this.aheadDb - 0.2
1295
+ else if (!this.jumped && wantedDb < this.aheadDb - 0.2) wantedDb = this.aheadDb - 0.2
1289
1296
  this.aheadDb = wantedDb
1297
+ this.jumped = false
1290
1298
  this.handover = Math.min(1, this.handover + handoverStep)
1291
1299
  } else {
1292
1300
  this.handover = Math.max(0, this.handover - handoverStep)
1293
- if (this.handover === 0) this.aheadDb = liveDb
1301
+ if (this.handover === 0) {
1302
+ this.aheadDb = liveDb
1303
+ this.jumped = false
1304
+ }
1294
1305
  }
1295
1306
  this.mix += Math.max(-crossfadeStep, Math.min(crossfadeStep, target - this.mix))
1296
1307
  const db = (liveDb + (this.aheadDb - liveDb) * this.handover) * this.mix
@@ -177,11 +177,18 @@ export const createPictureInPicture = (options: PictureInPictureOptions): Pictur
177
177
 
178
178
  const draw = (composite: HTMLCanvasElement, context: CanvasRenderingContext2D) => {
179
179
  context.drawImage(video, 0, 0, composite.width, composite.height)
180
- // Resolved per frame: the renderer replaces this element on every pipeline rebuild. A canvas
181
- // jassub has transferred reports the size of the last frame its worker committed, so the zero
182
- // check still keeps drawImage off a source with no dimensions to read.
180
+ // Resolved per frame: the renderer replaces this element on every pipeline rebuild. A new
181
+ // canvas keeps HTML's 300 by 150 default while jassub's worker boots, and copying it in Firefox
182
+ // then blocks the page for 10 s on OffscreenCanvasDisplayHelper::GetSurfaceSnapshot, so the
183
+ // renderer marks it `data-pending` until `ready` resolves.
183
184
  const surface = subtitles.querySelector('canvas')
184
- if (surface && surface.width > 0 && surface.height > 0 && Math.abs(video.currentTime - frameTime) <= STALE_SUBTITLES_S) {
185
+ if (
186
+ surface &&
187
+ !('pending' in surface.dataset) &&
188
+ surface.width > 0 &&
189
+ surface.height > 0 &&
190
+ Math.abs(video.currentTime - frameTime) <= STALE_SUBTITLES_S
191
+ ) {
185
192
  context.drawImage(surface, 0, 0, composite.width, composite.height)
186
193
  }
187
194
  }
@@ -301,6 +301,7 @@ export const createSubtitleRenderer = (options: SubtitleRendererOptions) => {
301
301
 
302
302
  const bootJassub = (header: SubtitleHeaderPart) => {
303
303
  const canvas = document.createElement('canvas')
304
+ canvas.dataset.pending = ''
304
305
  container.append(canvas)
305
306
  try {
306
307
  jassub = new JASSUB({
@@ -328,8 +329,13 @@ export const createSubtitleRenderer = (options: SubtitleRendererOptions) => {
328
329
  }
329
330
  // Not handed to the constructor, which attaches it with a `setVideo` nothing catches: that rejects with `ready`, so a
330
331
  // renderer that cannot start would leave an unhandled rejection in the host page.
331
- void jassub.setVideo(video).catch(startFailed)
332
- void jassub.ready.catch(rendererFailed)
332
+ const instance = jassub
333
+ void instance.setVideo(video).catch(startFailed)
334
+ // Cleared once the worker has booted: in Firefox, copying a transferred canvas while its worker
335
+ // starts blocks the page for 10 s on OffscreenCanvasDisplayHelper::GetSurfaceSnapshot.
336
+ void instance.ready.then(() => {
337
+ if (jassub === instance) delete canvas.dataset.pending
338
+ }, rendererFailed)
333
339
  for (const type of REPAINT_ON) video.addEventListener(type, onRepaintEvent)
334
340
  /*
335
341
  * The default face is the one font jassub loads LAZILY. Attachments are handed to the constructor
@@ -425,8 +425,9 @@ export const ProgressBar = () => {
425
425
  useEffect(() => {
426
426
  if (seekFraction === undefined || !duration) return
427
427
  if (!dragging || !isScrub.current) return
428
- player.seek(seekFraction * duration)
429
- }, [player, dragging, seekFraction, duration])
428
+ if (requestSeek) requestSeek(seekFraction * duration, true)
429
+ else player.seek(seekFraction * duration)
430
+ }, [player, requestSeek, dragging, seekFraction, duration])
430
431
 
431
432
  /*
432
433
  * Where the bar is drawn, which is not always where the element is.
@@ -198,11 +198,11 @@ export const usePlayback = (
198
198
  }, [player, playingAudio])
199
199
 
200
200
  /*
201
- * Counts the seeks asked for, so a seek that a newer one replaced never moves the playhead.
201
+ * Counts the seeks asked for, so a seek that a newer one replaced never moves the playhead, nor clears `seekingTo`.
202
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).
203
+ * A newer remuxer task (the newer seek's prepare, or the engine seek its move or a scrub starts) aborts the older
204
+ * seek's prepare, which then resolves as if its data were in. Firefox 153 landed on the older seek; Chrome 156 moved
205
+ * to it first, into ground with no data (2026-11-21).
206
206
  */
207
207
  const seeks = useRef(0)
208
208
 
@@ -215,17 +215,21 @@ export const usePlayback = (
215
215
  * is worse than the fault it avoids. So the playhead moves either when the data lands or when the
216
216
  * budget runs out, once, whichever happens first.
217
217
  *
218
- * A seek into buffered ground resolves immediately, so scrubbing inside the buffer is unaffected.
218
+ * A seek into buffered ground resolves immediately, and a scrub (`now`) never waits.
219
219
  */
220
- const requestSeek = useCallback((time: number) => {
220
+ const requestSeek = useCallback((time: number, now = false) => {
221
221
  const seek = ++seeks.current
222
222
  const controller = controllerRef.current
223
223
  // no budget means the feature is off: seek at once and do not spend a read preparing something
224
- // nobody is going to wait for
225
- if (!controller || seekPrepareBudgetMs <= 0) { player.seek(time); return }
224
+ // nobody is going to wait for. A seek that moves at once leaves none on its way.
225
+ if (!controller || seekPrepareBudgetMs <= 0 || now) {
226
+ player.setSourceState({ seekingTo: undefined })
227
+ player.seek(time)
228
+ return
229
+ }
226
230
 
227
231
  /*
228
- * Every call gets the data first. There is deliberately no "this looks like a drag" shortcut.
232
+ * Every settled seek gets the data first. There is deliberately no "this looks like a drag" shortcut.
229
233
  *
230
234
  * The first version of this guessed at drags from the gap between calls, and that is what let
231
235
  * the fault through in production: the seek bar reports a change on the PRESS and again on every
@@ -233,9 +237,9 @@ export const usePlayback = (
233
237
  * read as a drag, and the playhead jumped onto unbuffered ground before its data existed. Two
234
238
  * quick taps of the arrow keys would have done the same.
235
239
  *
236
- * The chrome knows what gesture it is in and now says so by only calling this for settled seeks,
237
- * which is knowledge rather than inference. Rapid calls are safe here anyway: each replaces
238
- * the last through `seeks`.
240
+ * The chrome knows what gesture it is in and says so: a scrub passes `now`, and only a settled
241
+ * seek waits, which is knowledge rather than inference. Rapid calls are safe here anyway: each
242
+ * replaces the last through `seeks`.
239
243
  */
240
244
  /*
241
245
  * A debug trace, off unless asked for.
@@ -284,13 +288,16 @@ export const usePlayback = (
284
288
  player.setSourceState({ seekingTo: time })
285
289
  const video = controller.videoElement
286
290
  const settled = () => {
287
- video?.removeEventListener('seeked', settled)
291
+ video?.removeEventListener('seeked', onSeeked)
288
292
  clearTimeout(giveUp)
289
- player.setSourceState({ seekingTo: undefined })
293
+ if (seeks.current === seek) player.setSourceState({ seekingTo: undefined })
290
294
  }
295
+ // Before this seek has moved, a seeked is an earlier seek landing (Firefox 153, 2026-11-21). A pipeline going away
296
+ // ends the prepare, so a rebuild's resume at this seek comes after the move.
297
+ const onSeeked = () => { if (moved) settled() }
291
298
  // a seek the element never completes must not leave the clock stuck on a time it never reached
292
299
  const giveUp = setTimeout(settled, SEEK_DISPLAY_LIMIT_MS)
293
- video?.addEventListener('seeked', settled)
300
+ video?.addEventListener('seeked', onSeeked)
294
301
 
295
302
  const deadline = setTimeout(() => { movedBecause = 'deadline'; move() }, seekPrepareBudgetMs)
296
303
  void controller
@@ -242,10 +242,13 @@ export type SourceState = {
242
242
  * Waiting is bounded by a deadline, so a source that cannot answer in time costs that deadline and
243
243
  * not the whole read.
244
244
  *
245
+ * `now` moves at once without waiting, as a scrub following the pointer does. Any call replaces a seek still
246
+ * waiting for its data.
247
+ *
245
248
  * Undefined for a media this player does not own, where there is no pipeline to prepare and the
246
249
  * caller should seek directly.
247
250
  */
248
- requestSeek?: (time: number) => void
251
+ requestSeek?: (time: number, now?: boolean) => void
249
252
 
250
253
  /**
251
254
  * One frame back or forward, pausing first. Undefined for a media whose frames this document cannot see, unless its