@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 +8 -0
- package/dist/engine/index.js +1 -1
- package/dist/engine/playback.d.ts +4 -3
- package/dist/engine/source-buffer.d.ts +0 -1
- package/dist/{engine-5XbZqrD3.js → engine-BZDbaSfM.js} +66 -67
- package/dist/index.js +271 -265
- package/dist/react/components/chrome.d.ts +3 -1
- package/dist/react/components/skip-chapter.d.ts +5 -1
- package/dist/remote/index.d.ts +17 -4
- package/dist/remote/index.js +17 -5
- package/dist/remote/protocol.d.ts +4 -2
- package/dist/volume-normalizer-worklet.js +40 -26
- package/package.json +2 -2
- package/src/lib/audio/loudness-analysis.ts +3 -3
- package/src/lib/audio/playback-tap.ts +3 -3
- package/src/lib/audio/volume-normalizer-worklet.d.ts +1 -1
- package/src/lib/audio/volume-normalizer-worklet.js +40 -26
- package/src/lib/engine/playback.ts +15 -17
- package/src/lib/engine/source-buffer.ts +2 -6
- package/src/lib/react/components/chrome.tsx +4 -2
- package/src/lib/react/components/skip-chapter.tsx +8 -2
- package/src/lib/react/video-player.tsx +12 -3
- package/src/lib/remote/index.ts +29 -6
- package/src/lib/remote/protocol.ts +6 -3
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
|
|
package/dist/engine/index.js
CHANGED
|
@@ -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-
|
|
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
|
|
27
|
-
* fragment, and the end of the file once read. The buffers
|
|
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,
|
|
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:
|
|
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,
|
|
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
|
-
},
|
|
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
|
-
},
|
|
314
|
+
}, ve = () => {
|
|
317
315
|
let e = s(L);
|
|
318
316
|
if (!e.length) return !0;
|
|
319
|
-
let t =
|
|
320
|
-
return
|
|
321
|
-
},
|
|
322
|
-
let t =
|
|
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
|
-
},
|
|
322
|
+
}, Se = () => {
|
|
325
323
|
let e = s(L).map((e) => e.end);
|
|
326
|
-
e.length && (q = Math.max(q, ...e)), U && (
|
|
327
|
-
},
|
|
328
|
-
B = !0, G = null, K = 0,
|
|
329
|
-
let
|
|
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:
|
|
332
|
-
if (I ||
|
|
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:
|
|
336
|
-
|
|
333
|
+
pts: e.timestampOffset,
|
|
334
|
+
from: i
|
|
335
|
+
}), r.byteLength && N?.({
|
|
337
336
|
type: "fragment",
|
|
338
|
-
data:
|
|
339
|
-
}),
|
|
337
|
+
data: r
|
|
338
|
+
}), o && N?.({ type: "end" }), r.byteLength && (await R(r), Se());
|
|
340
339
|
} catch (e) {
|
|
341
|
-
|
|
340
|
+
n === W && (Y = !1), X(e, I || n !== W);
|
|
342
341
|
} finally {
|
|
343
|
-
|
|
342
|
+
n === W && (B = !1);
|
|
344
343
|
}
|
|
345
|
-
},
|
|
344
|
+
}, Te = async () => {
|
|
346
345
|
let e = G;
|
|
347
346
|
if (e) try {
|
|
348
|
-
await R(e),
|
|
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
|
|
351
|
+
let t = await _e(!0).then(() => !0, () => !1);
|
|
353
352
|
if (G !== e) return;
|
|
354
353
|
if (t) {
|
|
355
|
-
U = !1, await
|
|
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
|
-
},
|
|
363
|
-
if (z || B || $ !== void 0 || I || !G && (U || !
|
|
364
|
-
let e = ++
|
|
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
|
|
374
|
+
await Te(), !n() && J && (J = !1, ie?.());
|
|
376
375
|
} catch (e) {
|
|
377
376
|
X(e, n());
|
|
378
377
|
} finally {
|
|
379
|
-
e ===
|
|
378
|
+
e === he && (z = !1);
|
|
380
379
|
}
|
|
381
|
-
},
|
|
382
|
-
let t =
|
|
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
|
-
},
|
|
385
|
-
if (!I && !(
|
|
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
|
|
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
|
|
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
|
-
},
|
|
399
|
-
let t = performance.now(), n = t -
|
|
397
|
+
}, je = 0, Me = null, Q, Ne = (e) => {
|
|
398
|
+
let t = performance.now(), n = t - je;
|
|
400
399
|
if (n >= te) {
|
|
401
|
-
|
|
400
|
+
je = t, Me = null, ae?.(e);
|
|
402
401
|
return;
|
|
403
402
|
}
|
|
404
|
-
|
|
403
|
+
Me = e, !Q && (Q = setTimeout(() => {
|
|
405
404
|
Q = void 0;
|
|
406
|
-
let e =
|
|
407
|
-
|
|
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
|
|
412
|
+
let Pe = 0, $;
|
|
414
413
|
F.push(() => {
|
|
415
414
|
$ && clearTimeout($);
|
|
416
415
|
});
|
|
417
|
-
let
|
|
416
|
+
let Fe = () => {
|
|
418
417
|
let t = n.currentTime, r = e.info.input.duration || n.duration;
|
|
419
|
-
r > 0 &&
|
|
420
|
-
let i = performance.now(), a = i -
|
|
421
|
-
if (
|
|
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,
|
|
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
|
-
|
|
428
|
+
De(e) || (U = !1, we(e));
|
|
430
429
|
}, ne);
|
|
431
430
|
}
|
|
432
431
|
};
|
|
433
|
-
n.addEventListener("seeking",
|
|
434
|
-
let
|
|
435
|
-
if (
|
|
436
|
-
|
|
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",
|
|
441
|
-
let
|
|
442
|
-
|
|
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(
|
|
443
|
+
return F.push(() => clearInterval(Re)), {
|
|
445
444
|
destroy: le,
|
|
446
|
-
prepareSeek:
|
|
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,
|
|
588
|
-
let { video: t, subtitles: n } = e, r = e.mode ??
|
|
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,
|
|
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 };
|