@banou/media-player 0.10.31 → 0.10.33

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/README.md CHANGED
@@ -94,6 +94,9 @@ reads as a browser bug rather than a missing asset. Serve both.
94
94
 
95
95
  `libavWorkerUrl` (`libav-wasm/build/worker.js`) is named individually and still copies fine.
96
96
 
97
+ Copy all three from the libav-wasm this package depends on. A worker from before libav-wasm 0.9.0 writes another
98
+ timeline and reports no `timestampOffset`, so playback fails at load.
99
+
97
100
  `cjkFontUrl` is this package's own `noto-sans-jp.otf` (`import cjkFontUrl from
98
101
  '@banou/media-player/noto-sans-jp.otf?no-inline&url'`), Noto Sans JP cut to the JIS X 0208 kanji. jassub's libass has no
99
102
  system font fallback, so without it Japanese in a style whose font has no Japanese, which is how releases set song
@@ -448,6 +451,11 @@ its published name so it stays an honest consumer.
448
451
  document.addEventListener('fullscreenchange', () => { player.fullscreen = !!document.fullscreenElement })
449
452
  player.addEventListener('chapterschange', () => console.log(player.chapters))
450
453
  ```
454
+
455
+ A page with something of its own in the corner of the far player's skip offer sets `player.endingOffered = false` to
456
+ take the offer of the last ending away. The read is the far player's own word, from after its render, with a
457
+ `chapterschange` event following each change: wait for the false before drawing over that corner, and a player that
458
+ cannot take it (a bare element, an older version) stays true.
451
459
  - `src/lib/react/` the player component, its chrome, and the hooks.
452
460
  - `src/lib/labels.ts` the chrome's text in English, and `src/lib/locales/` its other languages.
453
461
 
@@ -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-5XbZqrD3.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-BZDbaSfM.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 };
@@ -23,9 +23,9 @@ export type MediaChapter = {
23
23
  };
24
24
  /**
25
25
  * What the remuxer produced, in the order it was appended: the init segment and the input audio stream it carries,
26
- * a run at load and at every remuxer seek (`pts` is the timestampOffset its fragments are appended at), each
27
- * fragment, and the end of the file once read. The buffers are playback's own and may be appended again, so a
28
- * consumer copies what it keeps.
26
+ * a run at load and at every remuxer seek (`pts` is the timestampOffset its fragments are appended at, the same for
27
+ * every run, and `from` the time the run starts at), each fragment, and the end of the file once read. The buffers
28
+ * are playback's own and may be appended again, so a consumer copies what it keeps.
29
29
  */
30
30
  export type PlaybackOutput = {
31
31
  type: 'init';
@@ -35,6 +35,7 @@ export type PlaybackOutput = {
35
35
  } | {
36
36
  type: 'run';
37
37
  pts: number;
38
+ from: number;
38
39
  } | {
39
40
  type: 'fragment';
40
41
  data: ArrayBuffer;
@@ -7,6 +7,5 @@ export declare const getTimeRanges: (sourceBuffer: SourceBuffer) => TimeRange[];
7
7
  export declare const updateSourceBuffer: (sourceBuffer: SourceBuffer, mediaSource: MediaSource) => {
8
8
  appendBuffer: (buffer: ArrayBuffer | Uint8Array) => Promise<void>;
9
9
  unbufferRange: (start: number, end: number) => Promise<void>;
10
- updateTimestampOffset: (timestampOffset: number) => Promise<void>;
11
10
  endOfStream: (allowed?: () => boolean) => Promise<void>;
12
11
  };
@@ -74,9 +74,6 @@ var i = {
74
74
  return {
75
75
  appendBuffer: (t) => r(() => (e.appendBuffer(t), c(e))),
76
76
  unbufferRange: (t, n) => r(() => t >= n ? Promise.resolve() : (e.remove(t, n), c(e))),
77
- updateTimestampOffset: (t) => r(async () => {
78
- e.timestampOffset = t;
79
- }),
80
77
  endOfStream: (n = () => !0) => r(async () => {
81
78
  if (t.readyState === "open" && !e.updating && n()) try {
82
79
  t.endOfStream();
@@ -285,7 +282,7 @@ var i = {
285
282
  }, a = () => {
286
283
  try {
287
284
  let n = j.addSourceBuffer(g);
288
- n.mode = "segments";
285
+ n.mode = "segments", n.timestampOffset = e.timestampOffset;
289
286
  let r = e.info.input.duration;
290
287
  Number.isFinite(r) && r > 0 && (j.duration = r), i(), t(n);
291
288
  } catch (e) {
@@ -295,7 +292,7 @@ var i = {
295
292
  i(), n(o("The MediaSource closed before a SourceBuffer could be created"));
296
293
  };
297
294
  j.addEventListener("sourceopen", a, { once: !0 }), j.addEventListener("sourceclose", s, { once: !0 }), j.addEventListener("error", s, { once: !0 });
298
- }), { appendBuffer: R, unbufferRange: de, updateTimestampOffset: fe, endOfStream: pe } = l(L, j);
295
+ }), { appendBuffer: R, unbufferRange: de, endOfStream: fe } = l(L, j);
299
296
  await R(e.data), N?.({
300
297
  type: "init",
301
298
  data: e.data,
@@ -303,65 +300,67 @@ var i = {
303
300
  audioStreamIndex: a
304
301
  }), N?.({
305
302
  type: "run",
306
- pts: 0
303
+ pts: e.timestampOffset,
304
+ from: 0
307
305
  }), e.subtitles?.length && c.pushFragments(e.subtitles), x?.();
308
- let z = !1, B = !1, V = 0, H, me = () => H ?? n.currentTime, U = !1, he = !1, ge = 0, W = 0, G = null, K = 0, q = 0, J = !1, _e = 0, Y = !0, X = (e, t, n = !1) => {
306
+ let z = !1, B = !1, V = 0, H, pe = () => H ?? n.currentTime, U = !1, me = !1, he = 0, W = 0, G = null, K = 0, q = 0, J = !1, ge = 0, Y = !0, X = (e, t, n = !1) => {
309
307
  let r = e?.message === "Cancelled";
310
308
  t && r || (console.error(e), (!J || n) && (J = !0, re?.(r ? o("Reading the video file failed", void 0, { cause: e }) : e)));
311
- }, ve = async (e = !1) => {
309
+ }, _e = async (e = !1) => {
312
310
  if (V > 0 && !e) return;
313
311
  let t = n.currentTime, r = e ? T : S, i = e ? E : C, a = s(L), o = (e, t) => (Y = !1, de(e, t));
314
312
  a.length && a[0].start < t + r && await o(0, t + r);
315
313
  for (let { end: e } of a) e > t + i && await o(t + i, e);
316
- }, ye = () => {
314
+ }, ve = () => {
317
315
  let e = s(L);
318
316
  if (!e.length) return !0;
319
- let t = me(), n = e.find((e) => e.start <= t + k && t < e.end);
320
- return we() && Se(t) && (!n || n.start <= t) || n && n.end >= t + C ? !1 : !n || n.end < t + w;
321
- }, be = (e) => s(L).find((t) => t.start <= e + k && e < t.end), xe = () => be(n.currentTime), Se = (e = n.currentTime) => {
322
- let t = be(e);
317
+ let t = pe(), n = e.find((e) => e.start <= t + k && t < e.end);
318
+ return Ce() && xe(t) && (!n || n.start <= t) || n && n.end >= t + C ? !1 : !n || n.end < t + w;
319
+ }, ye = (e) => s(L).find((t) => t.start <= e + k && e < t.end), be = () => ye(n.currentTime), xe = (e = n.currentTime) => {
320
+ let t = ye(e);
323
321
  return e >= q - .1 || !!t && t.end >= q - .1;
324
- }, Ce = () => {
322
+ }, Se = () => {
325
323
  let e = s(L).map((e) => e.end);
326
- e.length && (q = Math.max(q, ...e)), U && (he = !0);
327
- }, we = () => U || he && (s(L).at(-1)?.end ?? 0) >= q - .1, Te = async (e) => {
328
- B = !0, G = null, K = 0, _e = e, Y = !0;
329
- let t = ++W;
324
+ e.length && (q = Math.max(q, ...e)), U && (me = !0);
325
+ }, Ce = () => U || me && (s(L).at(-1)?.end ?? 0) >= q - .1, we = async (t) => {
326
+ B = !0, G = null, K = 0, ge = t, Y = !0;
327
+ let n = ++W;
330
328
  try {
331
- let { data: n, pts: r, subtitles: i, finished: a } = await P.seek(e);
332
- if (I || t !== W || (a && (U = !0), i?.length && c.pushFragments(i), await fe(r), I || t !== W)) return;
333
- N?.({
329
+ let { data: r, pts: i, subtitles: a, finished: o } = await P.seek(t);
330
+ if (I || n !== W) return;
331
+ o && (U = !0), a?.length && c.pushFragments(a), N?.({
334
332
  type: "run",
335
- pts: r
336
- }), n.byteLength && N?.({
333
+ pts: e.timestampOffset,
334
+ from: i
335
+ }), r.byteLength && N?.({
337
336
  type: "fragment",
338
- data: n
339
- }), a && N?.({ type: "end" }), n.byteLength && (await R(n), Ce());
337
+ data: r
338
+ }), o && N?.({ type: "end" }), r.byteLength && (await R(r), Se());
340
339
  } catch (e) {
341
- t === W && (Y = !1), X(e, I || t !== W);
340
+ n === W && (Y = !1), X(e, I || n !== W);
342
341
  } finally {
343
- t === W && (B = !1);
342
+ n === W && (B = !1);
344
343
  }
345
- }, Ee = async () => {
344
+ }, Te = async () => {
346
345
  let e = G;
347
346
  if (e) try {
348
- await R(e), Ce(), G === e && (G = null, K = 0);
347
+ await R(e), Se(), G === e && (G = null, K = 0);
349
348
  } catch (t) {
350
349
  if (G !== e) return;
351
350
  if (t?.name === "QuotaExceededError") {
352
- let t = await ve(!0).then(() => !0, () => !1);
351
+ let t = await _e(!0).then(() => !0, () => !1);
353
352
  if (G !== e) return;
354
353
  if (t) {
355
- U = !1, await Te(xe()?.end ?? n.currentTime);
354
+ U = !1, await we(be()?.end ?? n.currentTime);
356
355
  return;
357
356
  }
358
357
  }
359
358
  if (K += 1, K < D) return;
360
359
  throw G = null, t;
361
360
  }
362
- }, De = async () => {
363
- if (z || B || $ !== void 0 || I || !G && (U || !ye())) return;
364
- let e = ++ge, t = W, n = () => I || e !== ge || t !== W;
361
+ }, Ee = async () => {
362
+ if (z || B || $ !== void 0 || I || !G && (U || !ve())) return;
363
+ let e = ++he, t = W, n = () => I || e !== he || t !== W;
365
364
  z = !0;
366
365
  try {
367
366
  if (!G) {
@@ -372,78 +371,78 @@ var i = {
372
371
  }), r && N?.({ type: "end" }), !e.byteLength)) return;
373
372
  G = e, K = 0;
374
373
  }
375
- await Ee(), !n() && J && (J = !1, ie?.());
374
+ await Te(), !n() && J && (J = !1, ie?.());
376
375
  } catch (e) {
377
376
  X(e, n());
378
377
  } finally {
379
- e === ge && (z = !1);
378
+ e === he && (z = !1);
380
379
  }
381
- }, Oe = (e) => s(L).some((t) => t.start <= e && e < t.end && t.end >= _e) && Ae(e), ke = (e) => s(L).some((t) => t.start <= e && e < t.end), Z = (e) => {
382
- let t = be(e);
380
+ }, De = (e) => s(L).some((t) => t.start <= e && e < t.end && t.end >= ge) && ke(e), Oe = (e) => s(L).some((t) => t.start <= e && e < t.end), Z = (e) => {
381
+ let t = ye(e);
383
382
  return t ? t.end - e : 0;
384
- }, Ae = (e) => Z(e) >= A || we() && Se(e), je = async (e) => {
385
- if (!I && !(ke(e) && Ae(e))) {
383
+ }, ke = (e) => Z(e) >= A || Ce() && xe(e), Ae = async (e) => {
384
+ if (!I && !(Oe(e) && ke(e))) {
386
385
  $ && clearTimeout($), $ = void 0, U = !1, V++, H = e;
387
386
  try {
388
- await Te(e);
387
+ await we(e);
389
388
  let t = W;
390
389
  for (let n = 0; n < ee && !(I || t !== W || U || Z(e) >= A); n++) {
391
390
  let t = Z(e);
392
- if (await De(), Z(e) <= t) break;
391
+ if (await Ee(), Z(e) <= t) break;
393
392
  }
394
393
  } finally {
395
394
  V--, H === e && (H = void 0);
396
395
  }
397
396
  }
398
- }, Me = 0, Ne = null, Q, Pe = (e) => {
399
- let t = performance.now(), n = t - Me;
397
+ }, je = 0, Me = null, Q, Ne = (e) => {
398
+ let t = performance.now(), n = t - je;
400
399
  if (n >= te) {
401
- Me = t, Ne = null, ae?.(e);
400
+ je = t, Me = null, ae?.(e);
402
401
  return;
403
402
  }
404
- Ne = e, !Q && (Q = setTimeout(() => {
403
+ Me = e, !Q && (Q = setTimeout(() => {
405
404
  Q = void 0;
406
- let e = Ne;
407
- Ne = null, !(e === null || I) && (Me = performance.now(), ae?.(e));
405
+ let e = Me;
406
+ Me = null, !(e === null || I) && (je = performance.now(), ae?.(e));
408
407
  }, te - n));
409
408
  };
410
409
  F.push(() => {
411
410
  Q && clearTimeout(Q);
412
411
  });
413
- let Fe = 0, $;
412
+ let Pe = 0, $;
414
413
  F.push(() => {
415
414
  $ && clearTimeout($);
416
415
  });
417
- let Ie = () => {
416
+ let Fe = () => {
418
417
  let t = n.currentTime, r = e.info.input.duration || n.duration;
419
- r > 0 && Pe(Math.min(Math.max(t / r, 0), 1));
420
- let i = performance.now(), a = i - Fe < ne;
421
- if (Fe = i, !Oe(t) && !(Y && (B || Z(t) > 0) && Math.abs(t - _e) < .001)) {
418
+ r > 0 && Ne(Math.min(Math.max(t / r, 0), 1));
419
+ let i = performance.now(), a = i - Pe < ne;
420
+ if (Pe = i, !De(t) && !(Y && (B || Z(t) > 0) && Math.abs(t - ge) < .001)) {
422
421
  if (U = !1, $ && clearTimeout($), !a) {
423
- $ = void 0, Te(t);
422
+ $ = void 0, we(t);
424
423
  return;
425
424
  }
426
425
  $ = setTimeout(() => {
427
426
  if ($ = void 0, I) return;
428
427
  let e = n.currentTime;
429
- Oe(e) || (U = !1, Te(e));
428
+ De(e) || (U = !1, we(e));
430
429
  }, ne);
431
430
  }
432
431
  };
433
- n.addEventListener("seeking", Ie), F.push(() => n.removeEventListener("seeking", Ie));
434
- let Le = !1, Re = () => {
435
- if (Le) return;
436
- Le = !0;
432
+ n.addEventListener("seeking", Fe), F.push(() => n.removeEventListener("seeking", Fe));
433
+ let Ie = !1, Le = () => {
434
+ if (Ie) return;
435
+ Ie = !0;
437
436
  let e = n.error;
438
437
  X(new b(`the media element failed: ${e?.message ?? "unknown"}`, { cause: e }), !1, !0);
439
438
  };
440
- n.addEventListener("error", Re), F.push(() => n.removeEventListener("error", Re));
441
- let ze = setInterval(() => {
442
- Le || n.error || (ve().catch(() => {}), De().catch((e) => X(e, !1)), we() && !G && Se() && j.readyState === "open" && pe(() => !B).catch(() => {}));
439
+ n.addEventListener("error", Le), F.push(() => n.removeEventListener("error", Le));
440
+ let Re = setInterval(() => {
441
+ Ie || n.error || (_e().catch(() => {}), Ee().catch((e) => X(e, !1)), Ce() && !G && xe() && j.readyState === "open" && fe(() => !B).catch(() => {}));
443
442
  }, 100);
444
- return F.push(() => clearInterval(ze)), {
443
+ return F.push(() => clearInterval(Re)), {
445
444
  destroy: le,
446
- prepareSeek: je,
445
+ prepareSeek: Ae,
447
446
  videoElement: n,
448
447
  selectSubtitleStream: (e) => c.selectStream(e),
449
448
  indexes: e.indexes ?? [],
@@ -584,8 +583,8 @@ var i = {
584
583
  } catch (e) {
585
584
  throw M(c), e;
586
585
  }
587
- }, ue = 1280, L = 1920, R = 250, de = 100, fe = () => typeof HTMLCanvasElement < "u" && "captureStream" in HTMLCanvasElement.prototype, pe = () => typeof document < "u" && typeof HTMLVideoElement < "u" && typeof HTMLVideoElement.prototype.requestPictureInPicture == "function" && !!document.pictureInPictureEnabled, z = () => typeof HTMLVideoElement < "u" && "mozCaptureStream" in HTMLVideoElement.prototype, B = () => fe() ? pe() ? "window" : z() ? "burn-in" : null : null, V = (e) => {
588
- let { video: t, subtitles: n } = e, r = e.mode ?? B() ?? "window", i = e.maxWidth ?? (r === "burn-in" ? L : ue), a, o, s, c = !1, l = !1, u = !1, d = !1, f, p = () => r === "burn-in" ? !!a : !!a && document.pictureInPictureElement === a.mirror, m = (e, r) => {
586
+ }, ue = 1280, L = 1920, R = 250, de = 100, fe = () => typeof HTMLCanvasElement < "u" && "captureStream" in HTMLCanvasElement.prototype, z = () => typeof document < "u" && typeof HTMLVideoElement < "u" && typeof HTMLVideoElement.prototype.requestPictureInPicture == "function" && !!document.pictureInPictureEnabled, B = () => typeof HTMLVideoElement < "u" && "mozCaptureStream" in HTMLVideoElement.prototype, V = () => fe() ? z() ? "window" : B() ? "burn-in" : null : null, H = (e) => {
587
+ let { video: t, subtitles: n } = e, r = e.mode ?? V() ?? "window", i = e.maxWidth ?? (r === "burn-in" ? L : ue), a, o, s, c = !1, l = !1, u = !1, d = !1, f, p = () => r === "burn-in" ? !!a : !!a && document.pictureInPictureElement === a.mirror, m = (e, r) => {
589
588
  r.drawImage(t, 0, 0, e.width, e.height);
590
589
  let i = n.querySelector("canvas");
591
590
  i && i.width > 0 && i.height > 0 && r.drawImage(i, 0, 0, e.width, e.height);
@@ -701,4 +700,4 @@ var i = {
701
700
  };
702
701
  };
703
702
  //#endregion
704
- export { b as a, M as c, s as d, l as f, j as i, u as l, a as m, B as n, x as o, i as p, le as r, re as s, V as t, y as u };
703
+ export { b as a, M as c, s as d, l as f, j as i, u as l, a as m, V as n, x as o, i as p, le as r, re as s, H as t, y as u };